views:

3667

answers:

3

(I know there is a topic in this but I can't find it)

How to I get the mouse position? I want to screen position.

I start my program I want to set to the current mouse position(I can't even get the mouse position)

Location.X = ??
Location.Y = ??

(I am making a note application)

Edit: This must happen before the form is created.

+3  A: 

You should use System.Windows.Forms.Cursor.Position: "A Point that represents the cursor's position in screen coordinates."

RichieHindle
+1  A: 

To get the position look at the OnMouseMove event. The MouseEventArgs will give you the x an y positions...

protected override void OnMouseMove(MouseEventArgs mouseEv)

To set the mouse position use the Cursor.Position property.

http://msdn.microsoft.com/en-us/library/system.windows.forms.cursor.position.aspx

klabranche
You can read from Cursor.Position as well.
Havenard
+2  A: 

Cursor.Position will get the current screen poisition of the mouse (if you are in a Control, the MousePosition property will also get the same value).

To set the mouse position, you will have to use Cursor.Position and give it a new Point:

Cursor.Position = new Point(x, y);

You can do this in your Main method before creating your form.

adrianbanks