AJBrasaca
Programmer
- Jul 19, 2013
- 2
I want to draw a line on the form that follow the mouse pointer. However, I need to erase the drawing from the previous line. What's wrong with my code?
var
Form1: TForm1;
oldX, oldY : integer;
implementation
{$R *.dfm}
procedure TForm1.FormMouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
var Rect : TRect;
begin
if (oldX <> 0) then begin
Rect.Top := 10;
Rect.Left := oldX;
Rect.Right := OldX;
Rect.Bottom := oldY - 10;
InflateRect(Rect, 1, 1);
InvalidateRect(Handle, @Rect,false);
end;
MoveToEx(Canvas.Handle, X, 10, nil);
LineTo(Canvas.Handle, X, Y - 10);
oldX := X;
oldY := Y;
end;
var
Form1: TForm1;
oldX, oldY : integer;
implementation
{$R *.dfm}
procedure TForm1.FormMouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
var Rect : TRect;
begin
if (oldX <> 0) then begin
Rect.Top := 10;
Rect.Left := oldX;
Rect.Right := OldX;
Rect.Bottom := oldY - 10;
InflateRect(Rect, 1, 1);
InvalidateRect(Handle, @Rect,false);
end;
MoveToEx(Canvas.Handle, X, 10, nil);
LineTo(Canvas.Handle, X, Y - 10);
oldX := X;
oldY := Y;
end;