Search Tools Links Login

VB6 Tutorial 61: Multiple Forms


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.

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:

Choose a form template

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

Choose a form template

'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.

About this post

Posted: 2018-06-03
By: vb6boy
Viewed: 2,479 times

Categories

VB6 Tutorial

Attachments

No attachments for this post


Loading Comments ...

Comments

No comments have been added for this post.

You must be logged in to make a comment.