473,654 Members | 3,066 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How can I use method in class that I created?

I wrote this class

class CLine
{
public float sX,sY,dX,dY,m,x ,y;
public void Draw (PaintEventArgs g)
{
//Graphics g = this.CreateGrap hics
();
Bitmap bm=new Bitmap(1,1);
bm.SetPixel(0,0 ,Color.Black);
m = (dY-sY)/(dX-sX);
if (m<=1)
{
for (x=sX;x<=dX;x++ )
{
y=sY+(x+sX)*m;

g.Graphics.Draw ImageUnscaled(b m,Convert.ToInt 32(x)
+512,-1*Convert.ToInt 32(Math.Round(y ))+384);
}
}
else
{
for (y=sY;y<=dY;y++ )
{
x=sX+(y+sY)*m;

g.Graphics.Draw ImageUnscaled(b m,Convert.ToInt 32
(Math.Round(x)) +512,-1*Convert.ToInt 32(y)+384);
}
}
}
}

What should I do if I wanna call Draw method? I've tried
below code but it doesn't work.

CLine first = new CLine();
first.sX = 0; first.sY = 0; first.dX = 300; first.dY = -
500;
first.Draw(); <== Problem's here!

Thank in advance for your help.
Nov 15 '05 #1
6 1766
The only problem I see here is that you call method

public void Draw (PaintEventArgs g)

without a PaintEventArgs object:
first.Draw() ; <== Problem's here!
Hans.
-----Original Message-----
I wrote this class

class CLine
{
public float sX,sY,dX,dY,m,x ,y;
public void Draw (PaintEventArgs g)
{
//Graphics g = this.CreateGrap hics
();
Bitmap bm=new Bitmap(1,1);
bm.SetPixel(0,0 ,Color.Black);
m = (dY-sY)/(dX-sX);
if (m<=1)
{
for (x=sX;x<=dX;x++ )
{
y=sY+(x+sX)*m;

g.Graphics.Draw ImageUnscaled(b m,Convert.ToInt 32(x)
+512,-1*Convert.ToInt 32(Math.Round(y ))+384);
}
}
else
{
for (y=sY;y<=dY;y++ )
{
x=sX+(y+sY)*m;

g.Graphics.Draw ImageUnscaled(b m,Convert.ToInt 32
(Math.Round(x) )+512,-1*Convert.ToInt 32(y)+384);
}
}
}
}

What should I do if I wanna call Draw method? I've tried
below code but it doesn't work.

CLine first = new CLine();
first.sX = 0; first.sY = 0; first.dX = 300; first.dY = -
500;
first.Draw() ; <== Problem's here!

Thank in advance for your help.
.

Nov 15 '05 #2
which is the problem ? do you got an error ?

class CLine has no constructor, you could create a constructor an pass your
members value through it...

"John" <an*******@disc ussions.microso ft.com> ha scritto nel messaggio
news:09******** *************** *****@phx.gbl.. .
I wrote this class

class CLine
{
public float sX,sY,dX,dY,m,x ,y;
public void Draw (PaintEventArgs g)
{
//Graphics g = this.CreateGrap hics
();
Bitmap bm=new Bitmap(1,1);
bm.SetPixel(0,0 ,Color.Black);
m = (dY-sY)/(dX-sX);
if (m<=1)
{
for (x=sX;x<=dX;x++ )
{
y=sY+(x+sX)*m;

g.Graphics.Draw ImageUnscaled(b m,Convert.ToInt 32(x)
+512,-1*Convert.ToInt 32(Math.Round(y ))+384);
}
}
else
{
for (y=sY;y<=dY;y++ )
{
x=sX+(y+sY)*m;

g.Graphics.Draw ImageUnscaled(b m,Convert.ToInt 32
(Math.Round(x)) +512,-1*Convert.ToInt 32(y)+384);
}
}
}
}

What should I do if I wanna call Draw method? I've tried
below code but it doesn't work.

CLine first = new CLine();
first.sX = 0; first.sY = 0; first.dX = 300; first.dY = -
500;
first.Draw(); <== Problem's here!

Thank in advance for your help.

Nov 15 '05 #3
Draw expects to be passed a PaintEventArgs. You can get this from
OnPaint, or you can rewrite it to use a graphics object and create the
graphics object before calling Draw.

Graphics g = this.CreateGrap hics(); // this assumes you are calling draw
from a windows form/control
Draw(g);
g.Dispose();

rewrite Draw to
public void Draw(Graphics g)

and change all references to g.Graphics in Draw to g
--
Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/
Nov 15 '05 #4
So how to fixed it?
-----Original Message-----
The only problem I see here is that you call method

public void Draw (PaintEventArgs g)

without a PaintEventArgs object:
>first.Draw() ; <== Problem's here!


Hans.
-----Original Message-----
I wrote this class

class CLine
{
public float sX,sY,dX,dY,m,x ,y;
public void Draw (PaintEventArgs g)
{
//Graphics g = this.CreateGrap hics
();
Bitmap bm=new Bitmap(1,1);
bm.SetPixel(0,0 ,Color.Black);
m = (dY-sY)/(dX-sX);
if (m<=1)
{
for (x=sX;x<=dX;x++ )
{
y=sY+(x+sX)*m;

g.Graphics.Draw ImageUnscaled(b m,Convert.ToInt 32(x)
+512,-1*Convert.ToInt 32(Math.Round(y ))+384);
}
}
else
{
for (y=sY;y<=dY;y++ )
{
x=sX+(y+sY)*m;

g.Graphics.Draw ImageUnscaled(b m,Convert.ToInt 32
(Math.Round(x ))+512,-1*Convert.ToInt 32(y)+384);
}
}
}
}

What should I do if I wanna call Draw method? I've tried
below code but it doesn't work.

CLine first = new CLine();
first.sX = 0; first.sY = 0; first.dX = 300; first.dY = -
500;
first.Draw( ); <== Problem's here!

Thank in advance for your help.
.

.

Nov 15 '05 #5
Yeah, I got an error. I think I can pass member value by
use this line, "first.sX = 0; first.sY = 0; first.dX =
300; first.dY = - 500;". So how can I fix it?
-----Original Message-----
which is the problem ? do you got an error ?

class CLine has no constructor, you could create a constructor an pass yourmembers value through it...

"John" <an*******@disc ussions.microso ft.com> ha scritto nel messaggionews:09******* *************** ******@phx.gbl. ..
I wrote this class

class CLine
{
public float sX,sY,dX,dY,m,x ,y;
public void Draw (PaintEventArgs g)
{
//Graphics g = this.CreateGrap hics
();
Bitmap bm=new Bitmap(1,1);
bm.SetPixel(0,0 ,Color.Black);
m = (dY-sY)/(dX-sX);
if (m<=1)
{
for (x=sX;x<=dX;x++ )
{
y=sY+(x+sX)*m;

g.Graphics.Draw ImageUnscaled(b m,Convert.ToInt 32(x)
+512,-1*Convert.ToInt 32(Math.Round(y ))+384);
}
}
else
{
for (y=sY;y<=dY;y++ )
{
x=sX+(y+sY)*m;

g.Graphics.Draw ImageUnscaled(b m,Convert.ToInt 32
(Math.Round(x)) +512,-1*Convert.ToInt 32(y)+384);
}
}
}
}

What should I do if I wanna call Draw method? I've tried
below code but it doesn't work.

CLine first = new CLine();
first.sX = 0; first.sY = 0; first.dX = 300; first.dY = -
500;
first.Draw(); <== Problem's here!

Thank in advance for your help.

.

Nov 15 '05 #6
private void YourPaintEvent( object sender,
System.Windows. Forms.PaintEven tArgs e)
{
CLine first = new CLine();
first.Draw(e.Gr aphics);
}
-----Original Message-----
So how to fixed it?
-----Original Message-----
The only problem I see here is that you call method

public void Draw (PaintEventArgs g)

without a PaintEventArgs object:
>first.Draw() ; <== Problem's here!


Hans.
-----Original Message-----
I wrote this class

class CLine
{
public float sX,sY,dX,dY,m,x ,y;
public void Draw (PaintEventArgs g)
{
//Graphics g = this.CreateGrap hics
();
Bitmap bm=new Bitmap(1,1);
bm.SetPixel(0,0 ,Color.Black);
m = (dY-sY)/(dX-sX);
if (m<=1)
{
for (x=sX;x<=dX;x++ )
{
y=sY+(x+sX)*m;

g.Graphics.Draw ImageUnscaled(b m,Convert.ToInt 32(x)
+512,-1*Convert.ToInt 32(Math.Round(y ))+384);
}
}
else
{
for (y=sY;y<=dY;y++ )
{
x=sX+(y+sY)*m;

g.Graphics.Draw ImageUnscaled(b m,Convert.ToInt 32
(Math.Round( x))+512,-1*Convert.ToInt 32(y)+384);
}
}
}
}

What should I do if I wanna call Draw method? I've triedbelow code but it doesn't work.

CLine first = new CLine();
first.sX = 0; first.sY = 0; first.dX = 300; first.dY = -500;
first.Draw() ; <== Problem's here!

Thank in advance for your help.
.

.

.

Nov 15 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
22514
by: Martin | last post by:
I'd like to be able to get the name of an object instance from within a call to a method of that same object. Is this at all possible? The example below works by passing in the name of the object instance (in this case 'myDog'). Of course it would be better if I could somehow know from within write() that the name of the object instance was 'myDog' without having to pass it as a parameter. //////////////////////////////// function...
9
11571
by: keith | last post by:
I created a class libery which has name space Assembly and class Assembly and compiled it. Then created a C# project and called a method in the external class e.g. Assembly dll; dll=Assembly.LoadFrom(@"c:\app\Assembly.dll");
0
1648
by: Cordell Lawrence | last post by:
Okay guys, We are wondering if this is a bug in Framework 2.0.40607 and looking for some clarification on the issue. Take a look at the folowing code. public delegate bool BoundryTest(int myVal);
2
1562
by: juli jul | last post by:
Hello I want to write get method of some object I create in other class: I am doing some like that: public ABC { get { return ABC; }
18
4727
by: JohnR | last post by:
From reading the documentation, this should be a relatively easy thing. I have an arraylist of custom class instances which I want to search with an"indexof" where I'm passing an instance if the class where only the "searched" property has a value. I expected to get the index into the arraylist where I could then get the entire class instance. However, the 'indexof' is never calling my overloaded, overrides Equals method. Here is the...
5
10287
by: Doru Roman | last post by:
Hi, Can somebody explain please the meaning and use of a STATIC method? Thanks, Doru
19
2429
by: zzw8206262001 | last post by:
Hi,I find a way to make javescript more like c++ or pyhon There is the sample code: function Father(self) //every contructor may have "self" argument { self=self?self:this; //every class may have this statement self.hello = function() {
9
1572
by: VK | last post by:
<OT>I am finishing TransModal 0.1 so planning to move it from alpha to beta stage.<OT> Besides that I am planning to write an introductory to inheritance schema currently used in Javascript programming. It will not be a manual of a "proper" way to use OOP inheritance but a compilation so a description of _all_ OOP paradigms that had been used or are being used in Javascript commercial solutions: starting from the prototype inheritance of...
0
1052
by: Gabriel Genellina | last post by:
En Tue, 29 Jul 2008 08:45:02 -0300, Themis Bourdenas <bourdenas@gmail.com> escribi�: In a very strict sense, I'd say that all those references to "method decorators" are wrong - because those "def" statements inside a "class" statement define functions, not methods. In that sense almost every Python programmer is wrong too: in this example class X:
0
8296
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8816
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8710
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8497
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8598
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7310
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6162
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
2
1928
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1598
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.