Hi PaulDares-7770,
You can use Graphics.DrawRectangle method to draw a rectangle in pictureBox paint event.
Here is my test code you can refer to.
private Point clickLast = Point.Empty;
private Point clickPrev = Point.Empty;
private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
{
clickPrev = clickLast;
clickLast = new Point(e.X,e.Y);
if (clickPrev == Point.Empty) return;
pictureBox1.Refresh();
}
private void pictureBox1_Paint(object sender, PaintEventArgs e)
{
int h = clickLast.Y - clickPrev.Y;
int w = clickLast.X - clickPrev.X;
System.Drawing.Pen pen = new System.Drawing.Pen(System.Drawing.Color.Red, 3);
e.Graphics.DrawRectangle(pen, clickPrev.X, clickPrev.Y, w, h);
clickLast = Point.Empty;
}
Test result:
Best Regards,
Daniel Zhang
If the response is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.