Adding New Forms to a Program


Adding New Forms to a Program

Each program you've written so far has used one form and a series of general-purpose dialog boxes for input and output. In many cases, dialog boxes and a form are sufficient for communicating with the user. But if you need to exchange more information with the user in a more customized manner, you can add additional forms to your program. Each new form is considered an object that inherits its capabilities from the System.Windows.Forms.Form class. The first form in a program is named Form1.vb. Subsequent forms are named Form2.vb, Form3.vb, and so on. (You can change the specific name for a form by using the Add New Item dialog box or by using Solution Explorer.) Each new form has a unique name and its own set of objects, properties, methods, and event procedures.

The following table lists several practical uses for additional forms in your programs.

Form or forms

Description

Introductory form

A form that displays a welcome message, artwork, or copyright information when the program starts

Program instructions

A form that displays information and tips about how the program works

Dialog boxes

Custom dialog boxes that accept input and display output in the program

Document contents

A form that displays the contents of one or more files and artwork used in the program

How Forms Are Used

Visual Basic gives you significant flexibility when using forms. You can make all the forms in a program visible at the same time, or you can load and unload forms as the program needs them. If you display more than one form at once, you can allow the user to switch between the forms, or you can control the order in which the forms are used. A form that must be addressed when it's displayed on the screen is called a dialog box. Dialog boxes (called modal forms in Visual Basic 6) retain the focus until the user clicks OK, clicks Cancel, or otherwise dispatches them. To display an existing form as a dialog box in Visual Basic 2005, you open it by using the ShowDialog method.

If you want to display a form that the user can switch away from, you use the Show method instead of the ShowDialog method. In Visual Basic 6, forms that can lose the application focus are called non-modal forms or modeless forms, and you will still see these terms being used. Most Windows applications use regular, non-modal forms when displaying information because they give the user more flexibility, so this style is the default when you create a new form in Visual Studio. Because forms are simply members of the System.Windows.Forms.Form class, you can also create and display forms by using program code.



Microsoft Visual Basic 2005 Step by Step
Microsoft Visual Basic 2005 Step by Step (Step by Step (Microsoft))
ISBN: B003E7EV06
EAN: N/A
Year: 2003
Pages: 168

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net