I am using this code to create a rectangle:
public static Rectangle RectangleFromPoints(Point a, Point b)
{
return new Rectangle(Math.Min(a.X, b.X),
Math.Min(a.Y, b.Y),
Math.Abs(a.X - b.X),
Math.Abs(a.Y - b.Y));
}
My issue is when I draw a horizontal or vertical line and then try to move it a.Y because a long negative number and throws an Overflow exception error.
EDIT
public override void Translate(Size s)
{
var oldBounds = this.ExpandedBounds;
_startLocator.Translate(s);
_endLocator.Translate(s);
Notify();
_canvas.Repaint(System.Drawing.Rectangle.Union(oldBounds, this.ExpandedBounds));
This is the code for moving the line. And this is ExpandedBounds:
public Rectangle ExpandedBounds
{
get
{
var rect = this.Bounds;
rect.Inflate((LocatorHandle.WIDTH / 2) + 1, (LocatorHandle.HEIGHT / 2) + 1);
return rect;
}
}