Chapter 9. Creating and Displaying New Forms

So far, this book has dealt mostly with building forms. Previous lessons explained how to add, arrange, and handle the events of controls on a single form.

In this lesson you learn how to display multiple forms in a single program. You learn how to add new forms to the project and how to display one or more instances of those forms. Once you've mastered these techniques, you can make programs that display any number of forms for all kinds of different purposes.

ADDING NEW FORMS

To add a new form to a project, open the IDE's Project menu and select Add Windows Form. Leave the Windows Form template selected, enter a descriptive name for the new type of form, and click Add. After you click Add, Visual Studio adds the new form type to the project. Figure 9-1 shows the new form in Solution Explorer.

FIGURE 9-1

Figure 9.1. FIGURE 9-1

Now you can add Labels, TextBoxes, Buttons, MenuStrips, and any other controls you want to the new form.

Note

Remember that to open a form in the Form Designer, double-click it in Solution Explorer.

UNDERSTANDING CLASSES AND INSTANCES

When you add a new form to the project, you're really adding a new type of form, not a new instance of that type. If you add the MakeUserForm type to a project and then run the program, you still see only the original startup form (with the catchy name Form1), and MakeUserForm is nowhere to be seen.

Form ...

Get Stephens' Visual Basic® Programming 24-Hour Trainer now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.