views:

110

answers:

2

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.

+1  A: 

Check out the Cursor.Position property

Galwegian
+3  A: 

Obtain the screen coordinates by using Cursor.Position, then convert to window coordinates invoking PointToClient on the window.

Konamiman
This worked just fine, though I was hoping there was already a build-in function to do it
Pieter888