|
-
Mar 13th, 2005, 05:15 AM
#1
Thread Starter
Frenzied Member
DrawLine
I am trying to draw a line on a form with the following code, but I get a strange error....
Code:
private void button2_Click(object sender, System.EventArgs e)
{
Graphics g;
Pen aPen = new Pen(Brushes.Black, 2);
g.DrawLine(aPen, 100,100,300,300);
}
Error:
C:\Documents and Settings\carsten\My Documents\Visual Studio Projects\sharp_test_obel\Form1.cs(228): Use of unassigned local variable 'g'
What am I doing wrong?
-
Mar 13th, 2005, 06:05 AM
#2
<?="Moderator"?>
Re: DrawLine
You are not creatning the graphics object
try
Code:
Graphics g = this.CreateGraphics();
Pen aPen = new Pen(Brushes.Black, 2);
g.DrawLine(aPen, 100,100,300,300);
-
Mar 13th, 2005, 06:09 AM
#3
Thread Starter
Frenzied Member
Re: DrawLine
Thanks That did the job
How would I do it in a picturebox?
-
Mar 13th, 2005, 06:14 AM
#4
<?="Moderator"?>
Re: DrawLine
use the same method just create the graphics from the picturebox instead, as far as i know it can be done with any control
Code:
Graphics g;
g = this.pictureBox1.CreateGraphics();
Pen aPen = new Pen(Brushes.Black, 2);
g.DrawLine(aPen, 100,100,300,300);
-
Mar 13th, 2005, 06:16 AM
#5
Thread Starter
Frenzied Member
Re: DrawLine
thanks
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|