Moving the Mouse Pointer

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
 
S

Stanimir Stoyanov

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)
 
A

Armin Zingler

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top