Multiple Forms

Handling multiple forms in your project is really very easy.

To add a form into your project, select the drop-down menu Add -> New Form, select the default form type, and you've got a new form. It's listed with your other form(s) in the Project Explorer.

When you run your program, Visual Basic always displays only the first form you had in your project. To display another form (we'll call it frmLaurel), you must do so in code, like this:

     frmLaurel.Show

To unload a form, you must also use code:

     Unload frmLaurel

There! Now you know how to display and shut down forms. To access controls in other forms, simply put the name of the form on the beginning of the control name, like this (assuming we have another form named frmHardy):

      name = frmLaurel.txtName.Text
      address = frmLaurel.txtAddress.Text
      frmHardy.Show
      frmHardy.Caption = "Employee " + name
      frmHardy.lblEmplAddress.Caption = address

And that's all you need to know to be able to handle multiple-form projects!


The Intro to Visual Basic homepage is hosted by GeoCities