4

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.

5
  • This question has absolutely nothing to do with visual studio. Please re-tag your question with the language you are interested in. Commented Nov 25, 2013 at 3:37
  • 1
    MouseMove will give you those coordinates. Commented Nov 25, 2013 at 3:37
  • Please remember to tag your question appropriately. Visual Studio is just an IDE - it tells us nothing about the language or framework you're using. I'm assuming it is C# and Windows Forms - I've retagged it accordingly. Please change it if that was not correct. Commented Nov 25, 2013 at 3:38
  • I wanted to tag Visual Basic but the tag did not exist. It is different than Basic, right ?. Thank you anyway. Commented Nov 25, 2013 at 4:12
  • @user3029534 Replace c# tag with vb.net. Welcome to Stack Overflow. Please remember to up-vote any answers that help, and accept the best one. Commented Nov 25, 2013 at 4:17

1 Answer 1

4

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.