Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Line drawing

Status
Not open for further replies.

AJBrasaca

Programmer
Jul 19, 2013
2
0
0
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? [banghead]


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;
 
Tek-Tips isn't a debugging or coding service. So you're going to have to do some work!

Where do you think you are erasing the previous line in your code?

Your code here draws the new line:

Code:
MoveToEx(Canvas.Handle, X, 10, nil);
LineTo(Canvas.Handle, X, Y - 10);

What you need to do is have similar code that erases the previous line (using the values of OldX and OldY). The simplest way to erase the line is to draw a line using the color of the form. By default this will be clBtnFace but you can obtain the color from Form1.Color if you have changed the default color.

Modify your code to do this. If it still doesn't work come back posting your code. Please use the

Andrew
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top