Controlling mouse pointer location

  • Thread starter Thread starter Dave Leach
  • Start date Start date
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
 
* "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'.
 
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!
 
Back
Top