Recipe 2.7. Setting the Startup Form for an Application


You want to indicate which of the several Windows Forms your application uses is the "main" form, the focal point of the application.


The application's main form is set through the Project Properties window. From that window, select the Application tab, and then use the " Startup form" field to select the form to use for the main form.


You can start up your Visual Basic application using the Windows Forms Application Framework, or without it. The " Enable application framework" field on the Application tab of the Project Properties window enables or disables this feature. When it's enabled, Visual Basic controls the startup process associated with your selected startup form. The Application Framework fires events during the startup process that you can use to include your own custom code. To access these events, click the View Application Events button on the Application panel of the Project Properties window.

If you disable the Application Framework, you have more control over the startup process. All Visual Basic applications begin by running a shared method named Main(), which will appear somewhere in your application's source code. You can use the "Startup form" field on the Application tab to tell Visual Basic to use the Main() method included with a specific form's code. If you do not supply such a method, Visual Basic will implicitly add one to the startup form, using code that looks something like this:

 Public Shared Sub Main()    Application.Run(My.Forms.Form1) End Sub 

You may add such a method to your startup form and include additional code as needed.

Visual Basic 2005 Cookbook(c) Solutions for VB 2005 Programmers
Visual Basic 2005 Cookbook: Solutions for VB 2005 Programmers (Cookbooks (OReilly))
ISBN: 0596101775
EAN: 2147483647
Year: 2006
Pages: 400 © 2008-2017.
If you may any questions please contact us: