Can you Draw Shapes on Forms/PictureBoxes?
-
I am making an app where you can click on an image (in a picturebox) to get X, Y, Width, and Height values. I would like to make it draw a rectangle of the specifyed X Y Width Height values on the PictureBox/Form once selected. Is this possible? Help is much appreciated, ~ZeldaFreak
-
I am making an app where you can click on an image (in a picturebox) to get X, Y, Width, and Height values. I would like to make it draw a rectangle of the specifyed X Y Width Height values on the PictureBox/Form once selected. Is this possible? Help is much appreciated, ~ZeldaFreak
You could always add code in the OnPaint event. If you just want to draw a single rectangle just declare a rectangle on the form object, then using mouse events once it is selected set the Selection Rectangle object to the appropriate values and then call
this.Invalidate();
It will force a repaint of the object. Inside the paint routine you can have code to only bother drawing the rectangle if a selection has been made. The actual drawing of the rectangle can be done via theSystem.Windows.Forms.PaintEventArgs
object which is passed to the routine. Simply use thee.Graphics.DrawRectangle();
method to draw the actual rectangle. An example of this called would be: e.Graphics.DrawRectangle(new Pen(Color.Red, 1), x, y, mySelection.Width, mySelection.Height); I am sure there is a better way out there but this should work.