Chapter 14 Managing Windows Forms and Controls at Run Time 373
Although this demonstration exercise was fairly simple, you can see that Visual Basic offers
you some flexibility in how you start your programs. You can specify the startup form, and
you can place code within that form’s Load event procedure to configure the program or
adjust its settings before the first form is actually loaded.
Console Applications
If you want to write a Visual Basic application that displays no graphical user interface
at all, consider writing a console application. This Visual Studio project type processes
input and output by using a command-line console (a character-based window also
known as the command prompt).
You can specify the console application type when you create your project by using
the New Project command on the File menu (select the Console Application template),
and you can convert an existing project into a console application by displaying the
Project Designer, clicking the Application tab, and then selecting Console Application
in the Application Type list box. Console applications begin execution within the Sub
Main procedure inside a code module, because there are no forms to display. You can
find out more about this topic by reviewing “Building Console Applications” in the
Visual Studio Help documentation.
Chapter 14 Quick Reference
To Do This
Add a new form to
a program
On the Project menu, click Add Windows Form, and then click Add.
Switch between forms
in your project, or
open hidden forms by
using program code
Use the Show or ShowDialog method. For example:
form2.ShowDialog()
You can also use the My.Forms object to display a form. For example:
My.Forms.HelpInfo.ShowDialog()
Hide the current form by using the Me object. For example:
Me.Visible = False
Display a form that is hidden by using the Me object. For example:
Me.ShowDialog()
Note that to use the Me object, your program code must be located
within the form you are manipulating.