private void CaptureBorderForm_MouseMove(object sender, MouseEventArgs e) { if (IsStartedRecord) { Cursor = Cursors.Default; return; } switch (FormActionType) { case MoveResizeAction.Move: case MoveResizeAction.ResizeLeft: case MoveResizeAction.ResizeTop: case MoveResizeAction.ResizeRight: case MoveResizeAction.ResizeBottom: case MoveResizeAction.ResizeTopLeft: case MoveResizeAction.ResizeTopRight: case MoveResizeAction.ResizeBottomRight: case MoveResizeAction.ResizeBottomLeft: Bounds = ControlMoveResizeUtil.CalcBounds(FormActionType, this, _startLoc, e.Location); break; default: ChangeCursor(e.X, e.Y); break; } Invalidate(); }
private void DoAction(Point currentLoc) { var bounds = ControlMoveResizeUtil.CalcBounds(MoveResizeAction, this, _startLoc, currentLoc); int diffX = bounds.X % PageBody.Grid; int diffY = bounds.Y % PageBody.Grid; int diffWidth = bounds.Width % PageBody.Grid; int diffHeight = bounds.Height % PageBody.Grid; switch (MoveResizeAction) { case MoveResizeAction.Move: if (diffX != 0) { bounds.X -= diffX; } if (diffY != 0) { bounds.Y -= diffY; } break; case MoveResizeAction.ResizeLeft: if (diffX != 0) { bounds.X -= diffX; bounds.Width += diffX; } break; case MoveResizeAction.ResizeTop: if (diffY != 0) { bounds.Y -= diffY; bounds.Height += diffY; } break; case MoveResizeAction.ResizeRight: if (diffWidth != 0) { bounds.Width -= diffWidth; } break; case MoveResizeAction.ResizeBottom: if (diffHeight != 0) { bounds.Height -= diffHeight; } break; case MoveResizeAction.ResizeTopLeft: if (diffY != 0) { bounds.Y -= diffY; bounds.Height += diffY; } if (diffX != 0) { bounds.X -= diffX; bounds.Width += diffX; } break; case MoveResizeAction.ResizeTopRight: if (diffY != 0) { bounds.Y -= diffY; bounds.Height += diffY; } if (diffWidth != 0) { bounds.Width -= diffWidth; } break; case MoveResizeAction.ResizeBottomRight: if (diffHeight != 0) { bounds.Height -= diffHeight; } if (diffWidth != 0) { bounds.Width -= diffWidth; } break; case MoveResizeAction.ResizeBottomLeft: if (diffHeight != 0) { bounds.Height -= diffHeight; } if (diffX != 0) { bounds.X -= diffX; bounds.Width += diffX; } break; } if (bounds.X < MinPoint.X) { bounds.X = MinPoint.X; } else if (bounds.X > MaxPoint.X) { bounds.X = MaxPoint.X; } if (bounds.Y < MinPoint.Y) { bounds.Y = MinPoint.Y; } else if (bounds.Y > MaxPoint.Y) { bounds.Y = MaxPoint.Y; } if (bounds.Width < MinSize.Width) { bounds.Width = MinSize.Width; } else if (bounds.Width > MaxSize.Width) { bounds.Width = MaxSize.Width; } if (bounds.Height < MinSize.Height) { bounds.Height = MinSize.Height; } else if (bounds.Height > MaxSize.Height) { bounds.Height = MaxSize.Height; } Bounds = bounds; }