C# MouseLeave 在显示上下文菜单之前触发?
我的表单上有一个上下文菜单,默认情况下应禁用某些选项,但当用户右键单击面板时启用。
按照我编写的方式,允许此特定菜单项的面板有两个事件处理程序:
- MouseEnter -> 。启用选项
- MouseLeave ->禁用 MouseEnter 选项
有效,但不幸的是,一旦用户右键单击,就会调用 MouseLeave。这意味着无论用户在何处右键单击,菜单项始终处于禁用状态。
有什么想法可以解决这个问题吗?
I have a ContextMenu on my Form, and some options should be disabled by default, but enabled when the user is right-clicking on a Panel.
The way I have written this, the Panel which allows this particular menu item has two event handlers:
- MouseEnter -> enables the option
- MouseLeave -> disables the option
MouseEnter works, but unfortunately MouseLeave is called as soon as the user right-clicks. This means no matter where the user is right-clicking, the menu item is always disabled.
Any ideas how to get around this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是不可避免的。一旦弹出上下文菜单,鼠标就会被菜单捕获,并且面板的 MouseLeave 事件将触发。你必须以不同的方式来做这件事。我想不出一个合适的选择,你这样做对我来说没有任何意义。面板有自己的 ContextMenuStrip 属性,也许这是一个线索。或者 ContextMenuStrip.SourceControl 属性。
This is inevitable. As soon as the context menu pops up, the mouse is captured by the menu and the MouseLeave event of the panel will fire. You are going to have to do this differently. I can't think of a decent alternative, it doesn't make any sense to me that you are doing this. The Panel has its own ContextMenuStrip property, maybe that's a lead. Or the ContextMenuStrip.SourceControl property.