user3651326
user3651326

Reputation: 122

Get mouse position from desktop not form

I want to create a windows form that when i click on a button it show mouse position and type of left click or right click in a label.I use this code:

this.Cursor = new Cursor(Cursor.Current.Handle);
label1.Text = Cursor.Position.X;
label1.Text+= Cursor.Position.Y;

but this show mouse position only from application form not anywhere,how to change it that return mouse position from desktop no a form?

thank you in advance.

Upvotes: 2

Views: 2784

Answers (2)

Beldi Anouar
Beldi Anouar

Reputation: 2180

Here is a good article how help you to getting Position of mouse cursor when clicked out side the form's : Get Cursor Position outside form

Upvotes: 2

Paulo Prestes
Paulo Prestes

Reputation: 494

You can add to the cursor position in the form, the position of the form in the screen.

Label1.Text = Form1.Location.X + Cursor.Position.X;
Label1.Text += Form1.Location.Y + Cursor.Position.Y;

Upvotes: 2

Related Questions