Form Events for Visual Basic 6.0 Users
There are some differences in form-event behavior between Visual Basic 6.0 and Visual Basic 2008.
In Visual Basic 6.0, the Initialize event is used to execute code before a form is loaded.
In Visual Basic 2008, initialization code must be added to the form constructor (Sub New()) after the call to InitializeComponent(), as in the following example:
' Visual Basic 6.0 Private Sub Form_Initialize() MsgBox("The form is loading") End Sub
A common use of the Initialize event is to show a "splash" form to display information while the form is loading. Visual Basic 2008 applications have a SplashScreen property that can be used to automatically display a form during application startup. For more information, see How to: Specify a Splash Screen for an Application (Visual Basic).
In Visual Basic 6.0, the Terminate event is used to execute code after a form is unloaded.
In Visual Basic 2008, the Terminate event is no longer supported. Termination code must be executed inside the Dispose method, before the call to MyBase.Dispose().
The Dispose method is called automatically for the main form in an application; you need to call it explicitly for any other form.
The following example demonstrates the differences.
' Visual Basic 6.0 Private Sub Form_Terminate() MsgBox "The form was terminated" End Sub
In Visual Basic 6.0, the Unload event has a Cancel argument; in Visual Basic 2008, it is replaced by the Closed event, which does not have a Cancel argument. If you need to cancel during unloading, use the Closing event instead.
Mouse Events for MDI Forms
In Visual Basic 6.0, MDI Forms support mouse events. In Visual Basic 2008, because an MDI Form has no client area to receive mouse events, the Click, MouseDown, MouseMove, and MouseUp events are no longer supported for MDI Forms.