C# 上下文菜单延迟事件

发布于 2024-12-26 15:59:00 字数 150 浏览 5 评论 0原文

我正在开发一个需要右键单击菜单的应用程序,我为此使用了 contextMenuStrip,但是当菜单打开并再次右键单击时,我的表单单击事件始终落后,因此触发最后一个事件而不是当前的一个。

我尝试过按下鼠标右键时关闭菜单并在释放鼠标右键时显示​​它,但它仍然做同样的事情。

I'm working on an application which needs a right click menu, I've used a contextMenuStrip for the this, but when the menu is open and I rightclick again my form click events are always one behind so the last event is triggered instead of the current one.

I've tried closing the menu when the right mouse button is pressed and showing it when it's released, but it still does the same thing.

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

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

发布评论

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

评论(1

就是爱搞怪 2025-01-02 15:59:00

我发现了问题,我正在更新 onMouseMove 事件中的鼠标位置并将其保留在我的静态 MouseState 类中,并且在上下文菜单打开时 onMouseMove 事件没有发生。我现在正在使用 form.PointToClient(Cursor.Position) 更新鼠标向下/向上/移动的鼠标

希望这可以帮助其他遇到类似问题的人。

I figured out the problem, I was updating the mouse position in an onMouseMove event and keeping it in my static MouseState class and the onMouseMove event wasn't happening while the context menu was up. I'm now updating the mouse on mouse down/up/move using form.PointToClient(Cursor.Position)

Hope this helps others with similar issues.

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