Controlling mouse pointer location

D

Dave Leach

I would like to position the mouse pointer to one corner
or the center of my C# application's main form when a
particular event occurs, probably tied to a change in
some parameter's value.

How can I control programmatically the mouse pointer
location?

Also, can I position the mouse pointer to the center of
a particular control?

Thanks,
Dave
 
H

Herfried K. Wagner [MVP]

* "Dave Leach said:
I would like to position the mouse pointer to one corner
or the center of my C# application's main form when a
particular event occurs, probably tied to a change in
some parameter's value.

How can I control programmatically the mouse pointer
location?

Also, can I position the mouse pointer to the center of
a particular control?

'Cursor.Position', 'Control.PointToClient', 'Control.PointToScreen'.
 
Y

Ying-Shen Yu[MSFT]

Hi Dave,
Thanks for your post!
You can use the Cursor.Position property to set the cursor location.
The Position is in screen coordinate, so you need convert the destinate
location from the client coordinate of your from to the screen coordinate.
The PointToScreen method will help you do this.
For example , to set your mouse cursor to the right -bottom corner of your
form you may use the following snippet.
<code>
Point rightBottom = new Point(ClientSize.Width,ClientSize.Height);
Cursor.Position = this.PointToScreen(rightBottom);
</code>
Does it solve your problem?
If you have anything unclear, please be free to reply to this group!
Thanks!

Best regards,

Ying-Shen Yu [MSFT]
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security

This posting is provided "AS IS" with no warranties and confers no rights.
You should not reply this mail directly, "Online" should be removed before
sending, Thanks!
 

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