Working with Multiple Forms in Visual Basic. Net

Working with Multiple Forms in Visual Basic. Net

Most of the applications developed in VB.Net require multiple forms. As far as, forms are of their basic importance in VB.Net programming, it is important to learn how to insert multiple forms in a project and how to make interactions among them.

This article will guide you through inserting multiple forms in a project and interacting between them.


Adding Multiple Forms

To add multiple forms in a project you need to;

Adding Multiple Forms

  • Open a new project (Windows Forms Application)
  • In Solution Explorer window, find Multiple Forms
  • Right click over it, then find Add
  • From the new list, find Windows Form
  • Click on it, give a name to your form and click Ok

VB.Net will then add a new form to your project.

Important: It is necessary to know that while working with multiple forms, you can never close your main (first) form until you do not close you whole project. i.e; when you run your project, the first window that appears will always remain open until you stop the execution of the program. If you close the main (first) form then the whole program will stop executing. However; you can use the method Hide() and hide your form to make it easier to work with other forms in the project.


Multiple Forms Interactions

Related: Event and Event Handlers in VB.Net

Visual Basic.Net is an event-driven programming language. In other words; events are necessary to execute the program. In order to interact among multiple forms, the program need to detect user or system events.

For example; if you want to show a second form in your project while working on the first form, you need to create an event. Here we have created a Button-Click event. Once the button is clicked the form desired will be shown.

Show() is a built-in procedure/ method in VB.Net. In case you are working in Form1 and you want to show Form2 you can make use of the above code. But if you are working in Form1 and you want to show or hide Form1 (reaching a form from inside the form), you should make use of the keyword (Me). Like;

Further; you can create events in a form that will interact or affect other forms in a project. Like;

In this code; whenever the text inside TextBox2 changes, the text for the Form1(Me) and the text for the Form2 changes (as specified in the code).


A Program with Multiple Forms

Code for the Form1:

Code for the Form2:

Output:

Leave your comments and suggestions, and ask for further tutorials/ articles.


Previous Event and Event Handler in Visual Basic.Net
Next Bubble Sort Algorithm, Code and Explaination

About author

Bahonar Javid
Bahonar Javid 43 posts

<p>* Computer Application Student<br /> * Co-Founder of www.codejow.com<br /> * Love to code and Learn new languages<br /> * Enjoy playing football</p>

View all posts by this author →

You might also like