获取控件上的单击点

发布于 2024-09-13 04:53:57 字数 244 浏览 1 评论 0原文

我在我的 C# Win 应用程序中使用旧的 ActiveX 控件。 它有一个 MouseUp 事件,其 eventArgs 正在传递我们单击的点的 X 和 Y,但对于我的场景,我使用其 ItemClick 事件,并且其 eventArgs 没有有关 X 和 Y 的信息。 但我需要知道它们才能显示我的弹出窗口...那么有没有一种方法可以找出用户右键单击的 X 和 Y 的位置,以便我可以将其传递给我的 contextMenuStrip.Show 方法。

谢谢

I am using an old ActiveX control in my C# Win App.
it has a MouseUp event that its eventArgs is passing the X and Y of the point that we have clicked but for my scenario I am using its ItemClick event and its eventArgs does not have the info about X and Y.
but I need to know them to show my pop-up... so is there a way I can find out what is the location of X and Y that user has right-clicked so I can pass it to my contextMenuStrip.Show method.

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

计㈡愣 2024-09-20 04:53:58

Control 类有一个静态只读 MousePosition 属性,这给出了屏幕上的鼠标坐标。您可以使用它来了解上下文菜单的位置。

来自 MSDN:

Control.MousePosition 属性

类型:System.Drawing.Point

包含坐标的点
鼠标光标相对于
屏幕左上角。

The Control class has a static readonly MousePosition property, this gives the mouse coordinates on the screen. You could use this to know where to position the ContextMenu.

From MSDN:

Control.MousePosition Property

Type: System.Drawing.Point

A Point that contains the coordinates of the
mouse cursor relative to the
upper-left corner of the screen.

挽容 2024-09-20 04:53:58

Cursor.Position 将获取光标当前的屏幕坐标。对于大多数用途来说,这已经足够好了,尽管鼠标可能会在单击和调用的处理程序之间移动。

Cursor.Position will get you the current screen coordinates of the cursor. For most uses this is good enough, even though the mouse can potentially move between the click and the handler being called.

浮云落日 2024-09-20 04:53:58

您需要获取获取屏幕位置的光标位置,然后从控件内调用 pointToClient 来获取控件的相关点。又名。 0,0 是控件的左上角。

this.PointToClient(Cursor.Position);

+1 其他答案引导我走向正确的方向。

You need to get the cursor position which gets the screen position, then call pointToClient from within the control to get the relevant point to the control. Aka. 0,0 is the top left of the control.

this.PointToClient(Cursor.Position);

+1 to other answers for leading me in the right direction.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文