CF - 如何在弹出ContextMenu时获取鼠标位置?

发布于 2024-09-02 13:34:13 字数 739 浏览 1 评论 0原文

我有一个无法解决的问题。

在我看来(显示地图)我创建了一个 contextMenu。 当调用上下文菜单时,我需要获取用户在地图上单击的位置。

这是我的问题:

在视图中,我已经有 onMouseDown 事件,它可以获取用户单击的坐标。

private void MapView_MouseDown(object sender, MouseEventArgs e)
    {
        this.lastMouseDownX = e.X;
        this.lastMouseDownY = e.Y;
    }

当调用 contextMenu 时,我需要相同的数据,但问题是 contextMenu 仅具有不保留我需要的数据的 EventArgs。此外...当用户按住鼠标一秒钟时,将调用 contextMenu,并且当调用它时,代码不会进入 onMouseDown 事件!它只是进入我的上下文菜单上的弹出事件......

我尝试将其放入我的弹出事件中,但坐标不正确。 Y 坐标与图表相差甚远。

private void servicesContextMenu_Popup(object sender, EventArgs e)
{
    this.lastMouseDownX = Control.MousePosition.X;
    this.lastMouseDownX = Control.MousePosition.Y;
}

帮助?

I have a problem i cannot solve.

In my view (that shows a map) i created a contextMenu.
When context menu is invoked i need to get the position where the user has clicked on the map.

Here is my problem:

In the view i already have onMouseDown event that gets me the coordinates where the user clicked.

private void MapView_MouseDown(object sender, MouseEventArgs e)
    {
        this.lastMouseDownX = e.X;
        this.lastMouseDownY = e.Y;
    }

When the contextMenu is invoked i need the same data, but the problem is that contextMenu only has EventArgs that dont keep the data i need. Furthermore ... contextMenu is invoked when user presses and holds mouse for a second and when its invoked the code does not enter onMouseDown event ! It just goes into popup event on my context menu....

I tried putting this in my popup event, but the coordinates are not ok. Y coordinate is way off the chart.

private void servicesContextMenu_Popup(object sender, EventArgs e)
{
    this.lastMouseDownX = Control.MousePosition.X;
    this.lastMouseDownX = Control.MousePosition.Y;
}

Help?

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文