开发者

C# MouseLeave triggered before context menu shown?

开发者 https://www.devze.com 2023-02-23 05:27 出处:网络
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.

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 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?


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消