Var igridsize: integer = 16; Procedure TFORM1.FormPaint (Sender: Tobject); Var i, J: Integer; Begin Self.doubleBuffered: = true; for i: = 0 to Self.Width Do for J: = 0 to Self. Height do if (j mod iGridSize = 0) and (i mod iGridSize = 0) then Self.Canvas.Pixels [i, j]: = clNavy; end; procedure TForm1.Shape1MouseDown (Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); begin if Button = mbLeft then begin Self.iOldX: = X; Self.iOldY: = Y; end; end; procedure TForm1.Shape1MouseMove (Sender: TObject; Shift: TShiftState; X, Y : Integer); begin if ssLeft in Shift then begin Shape1.Left: = Shape1.Left X - iOldX; Shape1.Top: = Shape1.Top Y - iOldY; end; end; procedure TForm1.Shape1MouseUp (Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); begin if Button = mbLeft then begin if (Shape1.Left - (Shape1.Left div iGridSize) * iGridSize)> (iGridSize div 2) then begin Shape1.Left: = (Shape1.left Div IGridsize) * IGRIDSIZE IGRIDSIZE; ELSE BEGIN SHA PE1.LEFT: = (Shape1.LEFT DIV IGRIDSIZE) * IGRIDSIZE; END; IF (Shape1.top - (Shape1.top Div iGridsize) * igridsize> (IGRIDSIZE DIV 2) THEN BEGIN Shape1.top: = (Shape1.top Div iGridsize) * IGRIDSIZE IGRIDSIZE; END ELSE BEGIN Shape1.top: = (Shape1.top Div iGridsize) * IGRIDSIZE; END; END;