public override void MoveHandle(PointF oldHandle, PointF newHandle)
{
PointF[] handles = GetHandles();
int handleIndex = Array.IndexOf(handles, oldHandle);
// Existing coordinates of the rectangle.
float left = rect.Left, top = rect.Top, right = rect.Right, bottom = rect.Bottom;
// Figure out which coord(s) moving this handle changes.
bool changeLeft = false, changeTop = false, changeRight = false, changeBottom = false;
switch (handleIndex) {
case 0: changeLeft = true; changeTop = true; break;
case 1: changeTop = true; break;
case 2: changeRight = true; changeTop = true; break;
case 3: changeLeft = true; break;
case 4: changeRight = true; break;
case 5: changeLeft = true; changeBottom = true; break;
case 6: changeBottom = true; break;
case 7: changeRight = true; changeBottom = true; break;
default:
Debug.Fail("bad handle"); break;
}
// Update the coordinates based on movement.
if (changeLeft) left = newHandle.X;
if (changeTop) top = newHandle.Y;
if (changeRight) right = newHandle.X;
if (changeBottom) bottom = newHandle.Y;
RectangleF newRect = Geometry.RectFromPoints(left, top, right, bottom);
// Update the rectangle.
RectangleUpdating(ref newRect, false, changeLeft, changeTop, changeRight, changeBottom);
rect = newRect;
}