Moving the Mouse Pointer

  • Thread starter Thread starter eBob.com
  • Start date Start date
E

eBob.com

Some research I did here led me to believe that I could position the mouse
pointer with the following code:

Windows.Forms.Cursor.Position = btnGo.Location

I don't know why that should work because I can't find a Cursor.Position
property in Windows.Forms. But Intellisense doesn't complain and it does
seem to move the cursor - but off the form altogether!

How can I position the mouse pointer so that it is over my Go button?

Thanks, Bob
 
You have to translate the btnGo.Location point to screen coordinates because
at that time it is relative to its (button's) owner, which is your Form:

Cursor.Position = Me.PointToScreen(Me.btnGo.Location)
 
eBob.com said:
Some research I did here led me to believe that I could position the
mouse pointer with the following code:

Windows.Forms.Cursor.Position = btnGo.Location

I don't know why that should work because I can't find a
Cursor.Position property in Windows.Forms. But Intellisense doesn't
complain and it does seem to move the cursor - but off the form
altogether!
How can I position the mouse pointer so that it is over my Go button?

The mouse position is measured in screen coordinates whereas the button's
location is in client coordinates of the containing Form:

Windows.Forms.Cursor.Position = PointToScreen(btnGo.Location)

or more general:

Windows.Forms.Cursor.Position = btnGo.Parent.PointToScreen(btnGo.Location)


Armin
 
Back
Top