Reputation: 5012
I want to be able to get the current location of the mouse pointer, relative from where my form window is. So if I would put my mouse on the top left of the form, it would give me the x and y values of x=0 and y=0, while the form itself might be in the middle of the screen.
Also I want to set the position of the mouse.
How can this be done in C#? I'm using a windows forms application.
Upvotes: 3
Views: 4634
Reputation: 50313
Obtain the screen coordinates by using Cursor.Position, then convert to window coordinates invoking PointToClient on the window.
Point p = this.PointToClient(Cursor.Position);
Upvotes: 5