Chase Mouse Have 95 Points

Hi, looking for code that will make a form chase the mouse. In other words, like where ever you move your mouse the form will follow. Working code please. Have 95 points or would offer more.
ssi49
ssi49Asked:
Who is Participating?
 
MaquiaveloConnect With a Mentor Commented:
 Hi! I've tried this code and seems to work.

  Hope it helps...

Paste this to BAS

Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long

Type POINTAPI
        x As Long
        y As Long
End Type

Add a timer control to the form, and paste the following code,

Private Sub Timer1_Timer()
    Dim a As POINTAPI
    Dim b As Long, c As Long
    Dim res&
   
    res& = GetCursorPos(a)
    Me.Move a.x * 10, a.y * 10
End Sub

  See ya...
0
 
BeedleGuisCommented:
will code to clip, or keep the mouse in the form work?? Thats alot easier than making the form chase the mouse.
0
 
ssi49Author Commented:
Maquiavelo
Thanks for the code. I am using vb 5.0 and when i run the program, the form doesn't do anything ? I move the mouse but the form just sits there. I pasted everything correctly. Any suggestions ?
Thanks
ssi49
0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
michelvCommented:
Be sure to set the timer interval to something other than 0, when 0 no timer events occur, interval = 1000 = 1 sec timer interval. So in this case, you may want to set the interval to 10:

timer1.interval = 10
timer1.enabled = true

Have you also pasted the sub Timer1_Timer into form1 (not into Module1)?

Also the me.move statement should be like this:

Me.Move a.x * Screen.TwipsPerPixelX, a.y * Screen.TwipsPerPixelY

Hope this helps...


0
 
ssi49Author Commented:
Works Real Nice, Thank You !
0
 
MaquiaveloCommented:
 Thanks michaelv! I think you deserve some points... :)
0
All Courses

From novice to tech pro — start learning today.