The VB.NET event firing sequence, when a form is loading, has a different order than VB6. It was ILRAP (Initialize, Reload, Resize, Activate, Paint), but is now TRLAP (TextChanged, Resized, Load, Activate, Paint). TextChanged and Resized events fire first because in the InitializeComponents method, the invocation of PerformLayout will force the TextChanged and Resized events to fire, if they are defined. However, if they fire before a form is loaded, this can often result in an exception error. To fix this, we have to set up form-level flag that is set to True once the form is loaded, and in TextChanged and Resized events, ignore them if the flag is not set. Why can’t TextChanged and Resized events simply be forced to be ignored until the form is loaded, automatically?
In the meantime, I have found that I can eradicate the frustration resulting from the early firing of TextChange and Resized events by declaring a Boolean flag at the procedure-level of the form, named mFormLoaded (Protected mFormLoaded As Boolean = False) that will be set to True (mFormLoaded = True) at the very bottom of the form’s Load event. Then, as the first statement in every existing TextChanged and Resized event I have on my form, I insert the following simple statement:
If Not mFormLoaded Then Return 'do not process this event until the form is loaded