C# 上下文菜单延迟事件
我正在开发一个需要右键单击菜单的应用程序,我为此使用了 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我发现了问题,我正在更新 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.