MouseEventHandler != this.controlname.MouseEnter ?

S

SeaNICK

I am trying to figure out how to use MouseEnter or MouseLeave events, and be
able to use the EventArgs to determine where the mouse cursor is. To my
great confusion, the MouseEnter and MouseLeave events are not
MouseEventHandlers.

so am I missing something, or is my .NET install messed up? it seems to me
that an event caused by a mouse being somewhere on the screen, should have
MouseEventArgs attached to it, not System.EventArgs.

but then again, maybe I am expecting too much, that the .NET framework be
logical. anyone have any advice on how to get this done, or should I just
assume events arent going to help me here and figure out how to determine
the location of the cursor manually?
thanks
NICK
 
N

Nicholas Paldino [.NET/C# MVP]

Nick,

You are right, the MouseEnter and the MouseLeave events do not have
position information associated with them. However, you can get the current
cursor position by calling the static Position property onthe Cursor class.
This will tell you where the cursor is in relation to the screen.

Because it is in screen coordinates, you have to convert them to local
coordinates (in relation to the control). In order to do this, you can pass
the coordinates to the PointToClient method on the Control class.

Hope this helps.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top