VB6 controls fire the Validate event first and then the Lost Focus event; if the Validate sets Cancel=True, then the Lost Focus event is never fired.
The sequence is the same regardless of how the end user moves the input focus away from the control. NET controls fire these events in the same sequence only if end users move the input focus by means of the keyword; if they use the mouse, the control fires a Lost Focus event, then the Validating event, and – if the validation fails – another Got Focus event to let the application know that the focus is again on the control. NET programs created by VB Migration Partner follow the . In most cases, the fact that the Lost Focus event fires before the Validate event doesn’t affect the application negatively.
The form, which is the root of all validation activities and configuration, has a property Auto Validate, which is set to Enable Prevent Focus Change (implicit validation occurs when the control loses focus).
However, as I also said in the last lesson, in many cases it is virtually impossible to account for all possible erroneous data.
Possibly a close exception to this rule would be when we use a List Box or Combo Box and allow the user to choose their entry from the control.
Back Color = vb White End Sub Private Sub Text1_Validate(Cancel as Boolean) Cancel = (Text1. In some applications, however, the code in the Text1_Lost Focus method might depend on some variable that has been set in the Validate event.
Text = "") End Sub Now consider the corresponding VB. If the end user clicks on a different control and Text1 contains an empty string, the Lost Focus event resets the background color to white, then the Validate event cancels the focus shift, and finally the Got Focus event changes the background color to yellow again. If this is the case, the converted code might fail or behave unexpectedly.