掌握控制点 [英] Get the point of click on a control
问题描述
我在C#Win App中使用的是旧版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.
谢谢
推荐答案
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.
从MSDN:
Control.MousePosition属性
Control.MousePosition Property
类型:System.Drawing.Point
Type: System.Drawing.Point
包含坐标的点 鼠标光标相对于 屏幕的左上角.
A Point that contains the coordinates of the mouse cursor relative to the upper-left corner of the screen.
这篇关于掌握控制点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!