C# MouseLeave 在显示上下文菜单之前触发?

发布于 2024-10-31 15:05:05 字数 269 浏览 0 评论 0原文

我的表单上有一个上下文菜单,默认情况下应禁用某些选项,但当用户右键单击面板时启用。

按照我编写的方式,允许此特定菜单项的面板有两个事件处理程序:

  • 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 技术交流群。

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

发布评论

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

评论(1

软糯酥胸 2024-11-07 15:05:05

这是不可避免的。一旦弹出上下文菜单,鼠标就会被菜单捕获,并且面板的 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.

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