Difference Between LostFocus Event and Leave Event of TextBox
Check the notes section on these links:
http://msdn.microsoft.com/en-us/library/system.windows.forms.control.lostfocus.aspx
http://msdn.microsoft.com/en-us/library/system.windows.forms.control.leave.aspx
According to MSDN, there is difference when changing focus of a control. The Leave
event occurs before a validation and LostFocus
occurs after validation.
UPDATE: 14 Feb 2019
I see that I'm still getting views and upvotes on the answer that I posted couple of years ago. It has now become imperative that I include a (rather important) quote from the MSDN links above to avoid confusion among new programmers (note the difference of order esp. in case of focus by using the mouse or by calling the Focus
method):
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 <--- before validation Validating -- |<--- validation Validated -- LostFocus <--- after validation
When you change the focus by using the mouse or by calling the Focus method, focus events occur in the following order:
Enter GotFocus LostFocus <--- before validation Leave <--- before validation Validating -- |<--- validation Validated --
N.B: Emphasis on text and indicators in the quote added by me
They happen at different points in the control's lifecycle. Depending on the method used, validation happens after Leave
and before LostFocus
.
See MSDN: http://msdn.microsoft.com/en-us/library/system.windows.forms.control.lostfocus.aspx
Leave() event means that first executes keyboard event and then executes mouse event where as Lost() event means that first executes mouse event and then executes keyboard event.