Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

mouse coordinates in MouseHover event?

I know how to retrieve the mouse coordinate in a PictureBox.Click event though e

In a PictureBox.MouseHover, e does not return such information.

How do I get the mouse coordinates in a MouseHover event ? Is there a way ?

Thanks in advance.

like image 268
user3029534 Avatar asked Sep 14 '25 04:09

user3029534


1 Answers

Control.MouseHover "occurs when the mouse pointer rests on the control."

A typical use of MouseHover is to display a tool tip when the mouse pauses on a control within a specified area around the control (the "hover rectangle"). The pause required for this event to be raised is specified in milliseconds by the MouseHoverTime property.

So this event is not raised only whenever the mouse is over the control - there is a delay associated. So the position is somewhat irrelevant, as the mouse could have moved somewhat during that delay.

Do you really need to be using this event? As Dan-o mentioned, MouseMove passes a MouseEventArgs which does provide the coordinates, as you request. It may be the right option, depending on what exactly you're trying to do.

To get the mouse position at any time though, you can use the Cursor.Position property. This will give you the screen coordinates of the cursor. From here, you can call the Control.PointToClient method, to get the coordinates relative to a particular Control.

like image 53
Jonathon Reinhart Avatar answered Sep 15 '25 20:09

Jonathon Reinhart



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!