Articles   Members Online:
-Article/Tip Search
-News Group Search over 21 Million news group articles.
-Delphi/Pascal
-CBuilder/C++
-C#Builder/C#
-JBuilder/Java
-Kylix
Member Area
-Home
-Account Center
-Top 10 NEW!!
-Submit Article/Tip
-Forums Upgraded!!
-My Articles
-Edit Information
-Login/Logout
-Become a Member
-Why sign up!
-Newsletter
-Chat Online!
-Indexes NEW!!
Employment
-Build your resume
-Find a job
-Post a job
-Resume Search
Contacts
-Contacts
-Feedbacks
-Link to us
-Privacy/Disclaimer
Embarcadero
Visit Embarcadero
Embarcadero Community
JEDI
Links
How to make a TButton flee from the mouse cursor Turn on/off line numbers in source code. Switch to Orginial background IDE or DSP color Comment or reply to this aritlce/tip for discussion. Bookmark this article to my favorite article(s). Print this article
26-Aug-02
Category
VCL-General
Language
Delphi All Versions
Views
87
User Rating
No Votes
# Votes
0
Replies
0
Publisher:
DSP, Administrator
Reference URL:
DKB
			Author: Tomas Rutkauskas

As a joke, I am trying to have a button on a form move around the form to avoid the 
mouse pointer. I was trying to use the OnMouseMove event of the form to accomplish 
this, but have not had any success. Does anybody know a quick way of doing this?

Answer:

1   procedure TMainForm.Button1MouseMove(Sender: TObject; Shift: TShiftState; 
2   X, Y: Integer);
3   var
4     NewPoint: TPoint;
5   begin
6     Randomize;
7     NewPoint.X := X;
8     NewPoint.Y := Y;
9     repeat
10      NewPoint.X := NewPoint.X + Random((Sender as TButton).Width div 2);
11      NewPoint.Y := NewPoint.Y + Random((Sender as TButton).Height div 2);
12    until
13      PtInRect(ClientRect, NewPoint) and not PtInRect((Sender as TButton).ClientRect, 
14  NewPoint);
15    (Sender as TButton).Left := NewPoint.X;
16    (Sender as TButton).Top := NewPoint.Y;
17  end;


			
Vote: How useful do you find this Article/Tip?
Bad Excellent
1 2 3 4 5 6 7 8 9 10

 

Advertisement
Share this page
Advertisement
Download from Google

Copyright © Mendozi Enterprises LLC