C# MouseLeave triggered before context menu shown?
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 opt开发者_JAVA技巧ion
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.
精彩评论