VB6 Tutorial 61: Multiple Forms

By | 2018-06-03

In Visual Basic 6, a windows application may have more than one window. Most of the Windows applications contain several windows. You can make a multiple windows software by adding some forms to your project as because forms are nothing but the windows of the final product.

Adding a form to your existing project

To add a form, go to Project >Add Form from the menu bar of the IDE. A window will appear to choose a form template.

You may change the Name property of the added form for your advantage. Remember, the forms are considered as objects.

Showing a form

You can show the newly added form using the Show method.

Syntax

Form.Show [Modal], [Owner form]

[Modal] means whether the form is modal or not. A modal form forces you to stay on the form until you close it or enter some data. You may have noticed this kind of form in several windows programs.

[Owner form] constant determines which form to be set as the owner form.

Example

You can make a form visible using any one of the following:

  • Form2.Show
  • Form2.Show vbModal
  • Form2.Show vbModeless
  • Form2.Show vbModal, Form1

Example

'in Form1 
Private Sub cmdShowForm2_Click()
    Form2.Show vbModal
End Sub
'in Form1 
Private Sub cmdShowForm2_Click()
    Form2.Show
    Unload Me   'unloads the current form
End Sub

Unloading a form

'in Form1 
Private Sub cmdUnloadForm2_Click()
    Unload Form2
End Sub

You can also use the Hide method.

Example

Form2.Hide

When you unload a form, it releases the memory which was allocated for the form. But the Hide method only hides the form, it doesn’t unload it from the memory.

Controlling a form from another form

You can change the properties of another form.

Example

'in Form1
Private Sub Command1_Click()
    Form2.BackColor = vbBlue
End Sub 

You can even set the controls’ properties which are on another form.

Example

'in Form1 
Form2.Text1.Text = "Welcome!"

In the next lesson, you’ll learn about the splash screen which is a special form template.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.