One Step Further: Specifying the Startup Object


One Step Further: Specifying the Startup Object

If your project contains more than one form, which form is loaded and displayed first when you run the application? Although Visual Basic normally loads the first form that you created in a project (Form1.vb), you can change the form that Visual Basic loads first by adjusting a setting in the Visual Studio Project Designer, a handy tool that I'll introduce now for the first time.

The following exercise shows you how to change the first form, or startup form, by using the Visual Studio Project Designer.

Switch the startup form from Form1 to Form2

  1. Click the Close Project command on the File menu, and then create a new project named My Startup Form.

  2. Display Form1.vb, if it isn't already visible.

  3. Click the Add Windows Form command on the Project menu.

    You'll add a new form to the project to demonstrate how switching the startup form works.

  4. Click Add to add the second form (Form2.vb) to Solution Explorer.

  5. Click My Startup Form Properties on the Project menu.

    The Project Designer appears, as shown here:

    graphic

    The Project Designer, formerly called a “property pages” dialog box because of its multiple screens of project properties, lets you adjust settings that apply to the entire project in one place. Here you'll use the Application tab and the Startup Form list box to specify a new startup form.

  6. Click the Startup Form arrow, and then click Form2.

    Visual Basic changes the startup form in your project from Form1 to Form2. When the program runs, Form2 will be displayed, and Form1 will appear only if it's opened using the Show or ShowDialog method.

  7. Click the Close button to close the Project Designer.

  8. Click the Start Debugging button.

    The program runs in the development environment, and Form2 appears.

  9. Click the Close button on the form to end the program.

  10. Close the project, and discard your changes—it is not necessary to save this simple demonstration project, and you're finished managing forms for now.

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 Contents section of the Visual Studio online Help. (Look for the article under the “Visual Studio” and “Types of Applications and Components” topics.)



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