VB6 beginners tutorial - Learn VB6

Advanced VB6 tutorial - Learn Advanced VB6

Systems Analysis - System analysis and Design tutorial for Software Engineering

You are here: Visual Basic > Advanced VB6 tutorial > Chapter 6

Form Methods and Their Effect on Form Events

The following sections discuss how referring to a form's members in code can load a form into memory, and how the form's Show and Hide methods relate to the loading and unloading of a form.

Implicitly Loading a Form

A form which is not yet in memory will load into memory automatically whenever you refer to any of its built-in methods or properties in code, or to any of the methods or properties of a control on the form.

Thus, statements such as

Form1.Caption = "Hello"
Form1.txtCity.Text = "Chicago"

would cause Form1 to load if it had not already been loaded. Causing a form to load in this way is known as implicit loading.

Show and Hide

These methods toggle a form's visibility. Calling a form's Show method sets the form's Visible property to True, and the form then becomes the application's active form. After a call to a form's Hide method, the form's Visible property will be False, and the form will no longer be the application's active form.

The Show method does more than simply toggle a form's Visible property: It also can accept a parameter that indicates the form's modal state.

  • A modeless form is the default way of managing a form in an application. When a form displays modelessly, the rest of the VB application continues any execution it needs to finish, and the user is able to freely navigate between this modeless form and any other forms in the application. Since modeless is the default state, modeless is implied when there is no reference to the parameter.

    MsgBox "Form1 visible" 'this line runs immediately

    If you wish to provide more clarity in your code, you can use the vbModeless parameter:

    Form1.Show vbModeless

  • A modal form demands more attention from the user. If the form is displayed modally, the user cannot navigate to other forms in the application. The form remains active until the form is closed. In addition, the calling procedure that originally shows the modal form with the call to its Show method will not resume until the form has been unloaded or hidden by either user action or code. You can display a form modally by calling the Show method with the vbModal constant as a parameter:

    Form1.Show vbModal
    'Next line won't run
    'till after Form1 is dismissed
    MsgBox "Finished Form1"

See "Show/Hide Methods Versus Load/Unload Statements."


<< Previous | Contents | Next >>

Home | About Us | Privacy Policy | Contact Us

Copyright © | All Rights Reserved