See Also Example
Form, MDI form.
Occurs when a form is loaded. For a startup form, occurs when an application starts, as the result of a Load statement, or as the result of a reference to an unloaded form's properties or controls.
Sub Form_Load ( )
Sub MDIForm_Load ( )
Typically, you use a Load event procedure to include initialization code for a formfor example, specifying default settings for controls, indicating contents to be loaded into combo boxes or list boxes, and initializing form-level variables.
In code, when you reference a property on an unloaded form, the form is automatically loaded, but is not automatically made visible unless the MDIChild property is True. If an MDI form is not loaded, and a child form is loaded, both the MDI form and the child form are automatically loaded and both become visible. Other forms are not shown until you either use the Show method or set the Visible property to True.
The following code in an MDI form Load event automatically loads an MDI child form (assuming Form1 has its MDIChild property set to True):
Dim NewForm As New Form1
NewForm.Caption = "New Form" ' Loads form by reference.
Since all child forms become visible when loaded, the Caption property reference loads the form and makes it visible.
Note When you create procedures for related events, such as Activate , GotFocus , Paint , and Resize , be sure that their actions don't conflict and that they don't cause recursive events.
Chapter 14, "Multiple-Document Interface (MDI) Applications"
Load Event Example
The example loads items into a combo box when a form is loaded. To try this example, paste the code into the Declarations section of a form that contains a combo box. Then press F5.
Sub Form_Load ()
Combo1.AddItem "Mozart" ' Add items to list.
Combo1.AddItem "Rock 'n Roll"
Combo1.ListIndex = 2 ' Set default selection.