You can draw an Ellipse on the pictureBox image using the following code:
public void drawEllipse(PictureBox pb, int x, int y, int w, int h, float Bwidth,Color col)
{
pb.Refresh();
Graphics g = pb.CreateGraphics();
Pen p = new Pen(col, Bwidth);
g.DrawEllipse(p, x, y, w, h);
p.Dispose();
g.Dispose();
}
In here, I grab the
picturebox
graphics using
pb.CreateGraphics()
so that I can draw on its surface. But drawing on the
PictureBox
only affects the pixels on the screen, not the pixels in the image. You can however, obtain the Graphics for the image. You can see that in the next example.
You can draw a line on the pictureBox
image using the following code:
public void drawline(PictureBox pb, Point p1, Point p2, float Bwidth,Color c1)
{
pb.Refresh();
Bitmap map=(Bitmap)pb.Image;
Graphics g = Graphics.FromImage(map);
Pen p = new Pen(c1, Bwidth);
g.DrawLine(p, p1, p2);
pb.Image = map;
p.Dispose();
g.Dispose();
}
After creating the graphics object(
g
), there are several predefined methods you can use to draw objects. Some are listed below:
g.DrawArc
g.DrawCurve
g.DrawBezier
g.DrawIcon
g.DrawImage
g.DrawPath
g.DrawRectangle
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.