I have two points created, like a line. I want to convert it as a rectangle. How should I do it?
For example this is how I draw the line. But I want it to be a Rectangle
private PointF start, end;
protected override void OnMouseDown(MouseEventArgs e)
{
start.X = e.X;
start.Y = e.Y;
}
protected override void OnMouseUp(MouseEventArgs e)
{
end.X = e.X;
end.Y = e.Y;
Invalidate();
}
How about:
new RectangleF(Math.Min(start.X, end.X),
Math.Min(start.Y, end.Y),
Math.Abs(start.X - end.X),
Math.Abs(start.Y - end.Y));
Basically this makes sure you really do present the upper-left corner as the "start", even if the user has created a line from the bottom-left to top-right corners.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With