Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The Difference Between MousEventArgs.Location and Cursor.Position

Tags:

c#

winforms

I don't understand why Cursor.Position is different from MouseEventArgs.Location, they should be the same, don't they?

Edit: The answer seems to suggest that Cursor.Position== PointToScreen(MouseEventArgs.Location), but my testing indicates otherwise.

like image 840
Graviton Avatar asked Dec 26 '09 07:12

Graviton


2 Answers

MouseEventArgs.Position is the mouse cursor position relative to the control during the event, at the time of the event.

Cursor.Position is the current mouse cursor position relative to the desktop.

like image 150
Tommy Carlier Avatar answered Oct 29 '22 20:10

Tommy Carlier


MouseEventArgs.location gives you the cursor position relative to the control during the event.

Windows.Forms.Cursor.Position gives you the cursor position relative to the desktop.

Obviously, these two need not be and are not same. The latter can be used without an event as such too unlike MouseEventArgs.Location

like image 39
UltraInstinct Avatar answered Oct 29 '22 21:10

UltraInstinct