Drawing over a picturebox
-
I have a c# program I've been writing which dynamically loads an image. It also dynamically loads an xml file which defines rectangles within the image. Each xml entry defines the upperleft coordinate on the image, and the width and height of the rectangle. What I need to do, is create outlines on the picturebox for each entry in the xml file. I'm not sure how to do this. Basically, over my loaded image, if there is an entry in the xml file, for example: 10,10, 50, 50 ... I need to draw a rectangle (outline, or full but semitransparent) over the picturebox at coordinates 10,10 width a height of 50 and width of 50. I've no idea where to start. Any help? Thanks.
-
I have a c# program I've been writing which dynamically loads an image. It also dynamically loads an xml file which defines rectangles within the image. Each xml entry defines the upperleft coordinate on the image, and the width and height of the rectangle. What I need to do, is create outlines on the picturebox for each entry in the xml file. I'm not sure how to do this. Basically, over my loaded image, if there is an entry in the xml file, for example: 10,10, 50, 50 ... I need to draw a rectangle (outline, or full but semitransparent) over the picturebox at coordinates 10,10 width a height of 50 and width of 50. I've no idea where to start. Any help? Thanks.
Here is some code used in a paint event. If it is not in an event with PaintEventArgs you will need to get a Graphics object in another way. private void Image_Paint(object sender, System.Windows.Forms.PaintEventArgs e) { Rectangle selRect = new Rectangle(0,0,0,0); Graphics selGraphics = null; int lineThickness = 2; selGraphics = e.Graphics; selRect.X = 10; selRect.Y = 10; selRect.Width=50; selRect.Height=50; Pen selPen = new Pen(Color.Black, lineThickness); selGraphics.DrawRectangle(selPen, selRect); }