I have a number of controls with ToolStrips containing buttons. I need to show or hide some of the buttons when the mouse enters the toolstrip. I know Mystery Meat is bad but it's what I've got to do.
The ToolStrip's MouseEnter
event fires when the mouse enters, b开发者_StackOverflow社区ut MouseLeave
does not always fire when the mouse leaves. I think this may be because the mouse has gone from being within a child, to being outside the control, without passing through the control itself.
How do I reliably detect when the mouse leaves a control?
MouseLeave fires only if the control owns the mouse capture.
What about using Global Hook: http://www.codeproject.com/KB/cs/globalhook.aspx
So you will be able to manage yourself the correct result.
I would stay away from global hooks.
Quote From : MSDN
Note You should use global hooks only for debugging purposes; otherwise, you should avoid them. Global hooks hurt system performance and cause conflicts with other applications that implement the same type of global hook.
Once your application has lost focus events are more difficult to deal with. Reevaluate your business rules.
Perhaps what you need to do is disable your application when loses focus. This will force the user to click on or tab to your application before using the tool strips. At that point you can just capture the Control.GotFocus event and perform any logic you want.
精彩评论