Имеется код, который рисует квадратик. Вопрос: как его прорисовывать чтобы значения не уходили в минус, то есть прорисовывать только по форме. Код:
| Код | unit Unit1;
interface
uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs;
type TForm1 = class(TForm) procedure FormMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer); private Capturing : bool; Captured : bool; StartPlace : TPoint; EndPlace : TPoint; { Private declarations } public { Public declarations } end;
var Form1: TForm1;
implementation
{$R *.dfm} function MakeRect(Pt1: TPoint; Pt2: TPoint): TRect; begin if pt1.x < pt2.x then begin Result.Left := pt1.x; Result.Right := pt2.x; end else begin Result.Left := pt2.x; Result.Right := pt1.x; end; if pt1.y < pt2.y then begin Result.Top := pt1.y; Result.Bottom := pt2.y; end else begin Result.Top := pt2.y; Result.Bottom := pt1.y; end; end;
procedure TForm1.FormMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer); begin if Captured then DrawFocusRect(Form1.Canvas.Handle,MakeRect(StartPlace, EndPlace)); StartPlace.x := X-64; StartPlace.y := Y-64; EndPlace.x := X+64; EndPlace.y := Y+64; DrawFocusRect(Form1.Canvas.Handle, MakeRect(StartPlace, EndPlace)); Capturing := true; Captured := true; end;
end.
|
|