Working with Multiple Forms in Visual Basic .NET
In this article, I will explain you about how to Add New Form to the Project and Working with Multiple Forms in Visual Basic .NET.
Add New Form to the Project
Many times we want to add new forms to our project. We can add a new form to the project by selecting Project->Add New Item from the main menu which displays a window which has many items to add to your project.
Select Windows Form from that window and click on Add button to add a new form to the project.
We can also add a new form from the Solution Explorer. To add a new form from the Solution Explorer, right-click on the project name in Solution Explorer and Select Add->Windows Formwhich again displays a window select Windows Form and click on Add button.
Now you have to make some changes if you want to display the form which you added when you run the application. For this right-click on the project name in Solution Explorer selectProperties which displays a Window.
On this window click the drop-down box named as Startup Form. By this you can able to see each and every form of your project.
Now which form you want to displayed when you run the application select that form and run your application. When you run the application, the form you assigned as Startup Form will be displayed.
Working with Multiple Forms
In visual Basic .NET we can work with multiple forms. For example, take three forms in your application Form1, Form2 and Form3. Now drag a buttons form the toolbox on Form1 andForm2. Now we want to open Form2 when a button on the Form1 is clicked and when we clicked the button on Form2, Form3 will displayed. Double click on Button1 on Form1 and place the code given below in the click event of the button.
Public Class Form1
Dim F2 As New Form2
'creating a reference to Form2
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)Handles Button1.Click
F2.Show()
End Sub
End Class
After that, Double click on Button1 on Form2 and place the code given below in the click event of the button.
Public Class Form2
Dim F3 As New Form3
'creating a reference to Form3
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)Handles Button1.Click
F3.Show()
End Sub
End Class
Summary
I hope this article will help you to understand about Add New Form to the Project and Working with Multiple Forms in Visual Basic .NET