Changing btnTestEmail.Enabled
to false will change the ActiveControl
, which fires the Leave
event.
According to MSDN:
When you change the focus by using the keyboard (TAB, SHIFT+TAB, and so on), by calling the Select or SelectNextControl methods, or by setting the ContainerControl.ActiveControl property to the current form, focus events occur in the following order:
Enter
GotFocus
Leave
Validating
Validated
LostFocus
What you can do:
What I would do to eliminate this behavior is unsubscribing the Leave
event and re-subscribing it after setting the Enabled
property to false.
Like this:
this.tabPage1.Leave -= new System.EventHandler(this.tabPage1_Leave);
btnTestEmail.Enabled = false;
this.tabPage1.Leave += new System.EventHandler(this.tabPage1_Leave);