WinForms: Textbox Leave event doesn't get fired after going to main menu
I found a reasonable workaround, I set the focus on the main menu manually:
EDIT: As suggested by @TcKs, I changed the event from ItemClicked to MenuActivate. Thanks very much for help!
private void menuStrip1_MenuActivate( object sender, EventArgs e )
{
menuStrip1.Focus();
}
You should use "Validating" and "Validated" events for checking user's input. Then if user go to another control "A", and the control "A" has property "CausesValidation" set to "true" ( its default value ) the "Validating" and "Validated" event will be fired.
The menu has "CausesValidation" property too.
Edit: Sorry, I forgot the "CausesValidation" in menu strip is our functionality and not built-in. But the check for validating is pretty simple:
private void menuStrip1_MenuActivate( object sender, EventArgs e ) {
bool ret = this.Validate( false );
if ( false == ret ) {
// user's input is wrong
}
}
Use any ContainerControl instead of "this", if you want check the validation in another control than the "this" form. For example in MDI Child window.