How to draw multiple rectangle in Picturebox using c#?
I want to draw multiple rectangles on Mousemove event.
I have tried the below code to draw single rectangle in picturebox but not multple rectangles
bool m_Drawing = false;
private void pictureBox1_MouseMove(object sender, MouseEventArgs e)
{
if (m_Drawing)
{
selection = RectangleFromPoints(m_Start, e.Location);
//Update selection
pictureBox1.Invalidate();
}
if (mouseDown)
{
ep = e.Location;
pictureBox1.Invalidate();
}
}
private Rectangle RectangleFromPoints(Point p1, Point p2)
{
int x = 0;
int y = 0;
if (p1.X <= p2.X)
{
x = p1.X;
}
else
{
x = p2.X;
}
if (p1.Y <= p2.Y)
{
y = p1.Y;
}
else
{
y = p2.Y;
}
return new Rectangle(x, y, Math.Abs(p1.X - p2.X), Math.Abs(p1.Y - p2.Y));
}
private void pictureBox1_Paint(object sender, PaintEventArgs e)
{
if (selection != null)
{
//There is a selection rectangle so draw it
e.Graphics.FillRectangle(hbr, selection);
}
}
Please help me on this.