Hi Patric,
A bunch of events are fired when the control loses the focus.
The right order is:
Leave
Validating
Validated
LostFocus
According to the event order above. You will receive LostFocus only if the
focus is actually lost and Leave as a inforamtion when request for changing
the focus has arrived. Validating event handler can cancel the request and
it is posible to receive Leave, but not to receive LostFocus.
Anyway there is a bug in the framework and this order is valid only when the
focus has been chaged using the TAB key to circle among the controls. If you
use the mouse for changing the focus (which is most often used I think) the
event order is:
LostFocus
Leave
Validating
Validated
You can see that you will receive LostFocus first and then the others
events. Validating event handler can cancel the operation and the focus
won't be changed even though you have received LostFocus.
So, the LostFocus is not reliable.
I haven't seen good workaround for this bug. Some people suggest catching
Windows messages, other using some special flags inside the form class. But
I think there is no universal cure for this. Until MS don't fix this the
best workaround depends on the application logic.