INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

Line drawing

Line drawing

(OP)
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;

RE: Line drawing

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

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close