VB6 Tutorial 61: Multiple Forms

Posted On 2018-06-03 by VB6Boy
Keywords: visual,basic,vb6,visualbasic,tutorial,basic,beginner
Tags: VB6 Tutorials 
Views: 34


Looking for the more of the VB6 Tutorial? Here is the tutorial index.

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:

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

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.

Looking for the more of the VB6 Tutorial? Here is the tutorial index.


About the Author

has posted a total of 101 articles.


Comments On This Post

No comments on this post yet!


Do you have a thought relating to this post? You can post your comment here. If you have an unrelated question, you can use the Q&A section to ask it.

Or you can drop a note to the administrators if you're not sure where you should post.


Your IP address is:54.159.91.117

Before you can post, you need to prove you are human. If you log in, this test goes away.


Code Links