S
Steve Long
Hello, (total GDI newbie)
I'm having trouble drawing just a simple line to display in a picturebox. I
just want a straight, dotdash line.
I have two methods, one works and one doesn't (it cause an exception to be
thrown):
This one works but it's not the results I want.
private void CreateImage1()
{
Bitmap b = new Bitmap(100, 100);
Graphics g = Graphics.FromImage(b);
g.DrawEllipse(Pens.Red, new RectangleF(0, 0, b.Width, b.Height));
pb1.Image = b;
g.Dispose();
}
This one cause the exception to be thrown:
private void CreateImage()
{
Bitmap bmp = new Bitmap(100, 100);
Graphics g = Graphics.FromImage(bmp);
Pen p = new Pen(Color.AliceBlue, 2);
p.DashStyle = System.Drawing.Drawing2D.DashStyle.DashDot;
Point p1 = new Point(pb1.Left);
Point p2 = new Point(pb1.Right);
g.DrawLine(p, p1, p2);
pb1.Image = bmp;
g.Dispose();
bmp.Dispose();
}
Anybody know what I'm having these problems?
I appreciate your help btw.
Steve
I'm having trouble drawing just a simple line to display in a picturebox. I
just want a straight, dotdash line.
I have two methods, one works and one doesn't (it cause an exception to be
thrown):
This one works but it's not the results I want.
private void CreateImage1()
{
Bitmap b = new Bitmap(100, 100);
Graphics g = Graphics.FromImage(b);
g.DrawEllipse(Pens.Red, new RectangleF(0, 0, b.Width, b.Height));
pb1.Image = b;
g.Dispose();
}
This one cause the exception to be thrown:
private void CreateImage()
{
Bitmap bmp = new Bitmap(100, 100);
Graphics g = Graphics.FromImage(bmp);
Pen p = new Pen(Color.AliceBlue, 2);
p.DashStyle = System.Drawing.Drawing2D.DashStyle.DashDot;
Point p1 = new Point(pb1.Left);
Point p2 = new Point(pb1.Right);
g.DrawLine(p, p1, p2);
pb1.Image = bmp;
g.Dispose();
bmp.Dispose();
}
Anybody know what I'm having these problems?
I appreciate your help btw.
Steve