I'm drawing a line on a Form and when it finished will be draw a rectangle on line. I need to resize the line after clicking on the rectangle. Any way to do that?
This before:
protected override void OnPaint(PaintEventArgs e)
{
e.Graphics.DrawLine(Pens.Red, start.X, start.Y, end.X, end.Y);
if (isMouse == false )
{
rect1.X = start.X - 5;
rect1.Y = start.Y - 5;
rect1.Width = 10;
rect1.Height = 10;
rect2.X = end.X - 5;
rect2.Y = end.Y - 5;
rect2.Width = 10;
rect2.Height = 10;
e.Graphics.DrawRectangle(Pens.Blue, rect1.X, rect1.Y,rect1.Width, rect1.Height);
e.Graphics.DrawRectangle(Pens.Blue, rect2.X, rect2.Y, rect2.Width, rect2.Height);
}
base.OnPaint(e);
}
private void Form1_MouseDown(object sender, MouseEventArgs e)
{
if (start.X == 0 && start.Y == 0)
{
isMouse = true;
start = e.Location;
}
else {
resize = true;
}
}
private void Form1_MouseMove(object sender, MouseEventArgs e)
{
if (isMouse == true) {
end = e.Location;
}
if (rect1.Contains(e.Location)&&resize ) {
start = e.Location;
}
else if (rect2.Contains(e.Location)&&resize) {
end = e.Location;
}
Refresh();
}
private void Form1_MouseUp(object sender, MouseEventArgs e)
{
if (isMouse == true)
{
end = e.Location;
isMouse = false;
}
}
This will be after: