MouseHover 事件中的鼠标坐标? [英] mouse coordinates in MouseHover event?

查看:55
本文介绍了MouseHover 事件中的鼠标坐标?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道如何在 PictureBox.Click 事件中检索鼠标坐标虽然 e

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

PictureBox.MouseHover 中,e 不会返回此类信息.

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

如何在 MouseHover 事件中获取鼠标坐标?有办法吗?

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

提前致谢.

推荐答案

Control.MouseHover 当鼠标指针停留在控件上时发生."

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

MouseHover 的一个典型用途是当鼠标在控件周围指定区域(悬停矩形")内的控件上暂停时显示工具提示.引发此事件所需的暂停时间由 MouseHoverTime 属性指定,以毫秒为单位.

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.

你真的需要使用这个事件吗?正如 Dan-o 提到的MouseMove 通过 MouseEventArgs 确实提供了坐标,根据您的要求.这可能是正确的选择,具体取决于您想要做什么.

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.

要在任何时间获取鼠标位置,您可以使用 Cursor.Position 属性.这将为您提供光标的屏幕坐标.从这里,您可以调用 Control.PointToClient 方法,获取相对于特定 Control 的坐标.

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.

这篇关于MouseHover 事件中的鼠标坐标?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆