Difference between revisions of "Hiding and Showing Forms in Visual Basic"

From Techotopia
Jump to: navigation, search
(Creating an Application with Multiple Forms)
Line 4: Line 4:
  
 
== Creating an Application with Multiple Forms ==
 
== Creating an Application with Multiple Forms ==
 +
 +
Before we can look at hiding and showing Forms we first need to create an application in Visual Studio which contains more than one form. Begin by starting Visual Studio and creating a new Windows Application project called vbShowForm (see [[Creating a New Visual Basic Project]] for details).
 +
 +
Visual Studio will prime the new project with a single form. Click on the Form to select it and, using the ''Properties'' panel change the ''Name'' of the form to ''mainForm''. Next we need to add a second form. To do this, click on the ''Add New Item'' in the Visual Studio toolbar to invoke the ''Add New Item'' window:
 +
 +
[[Image:Examp.jpg]]
 +
 +
The ''Add New Item'' window allows new items of various types to be added to the project. For this example we jusy need to add a new Windows Form to the our application. With ''Windows Form'' selected in the window click on ''Add''. Visual Studio will now display an additional tab containing the second form:
 +
 +
[[Image:Examp.jpg]]
 +
 +
Switch between the two forms by clicking on the respective tabs. With Form2 visible click on the form and change the name of the form in the ''Properties'' panel to ''subForm''.
 +
 +
Now that we have created an application with two forms the next step is provide a mechanism for hiding and showing ''subForm''.

Revision as of 15:54, 19 July 2007

When developing a Windows application using Visual Basic it is highly likely that the application will consist of multiple forms (otherwise known as windows). It is unlikely, however, that all of those forms will need to be displayed as soon as the application starts up. In fact, it is likely that most of the forms will remain hidden until the user performs some action that requires a form to be displayed.

In this chapter we will cover the topic of hiding and showing forms when developing applications in Visual Basic.

Creating an Application with Multiple Forms

Before we can look at hiding and showing Forms we first need to create an application in Visual Studio which contains more than one form. Begin by starting Visual Studio and creating a new Windows Application project called vbShowForm (see Creating a New Visual Basic Project for details).

Visual Studio will prime the new project with a single form. Click on the Form to select it and, using the Properties panel change the Name of the form to mainForm. Next we need to add a second form. To do this, click on the Add New Item in the Visual Studio toolbar to invoke the Add New Item window:

File:Examp.jpg

The Add New Item window allows new items of various types to be added to the project. For this example we jusy need to add a new Windows Form to the our application. With Windows Form selected in the window click on Add. Visual Studio will now display an additional tab containing the second form:

File:Examp.jpg

Switch between the two forms by clicking on the respective tabs. With Form2 visible click on the form and change the name of the form in the Properties panel to subForm.

Now that we have created an application with two forms the next step is provide a mechanism for hiding and showing subForm.