7.6 Designating the Initial Windows Form

 <  Day Day Up  >  

You have several defined forms in your application and you want to change the form that is initially displayed to the user .


Technique

Modify the static Main method, which was created when your project was initially created. Change the Application.Run method by creating an object instance of the form you want to initially display.

Another way to specify the initial form is to change a project property. First, create a static Main method in each form class. Within each of these Main methods , call the Application.Run method, passing an object instance of that form. Next, click on Project, Properties from the main menu (Alt+P, P) and select the General property page. Change the Startup Object property by selecting the name of the form you want initially displayed from the drop-down box.

Comments

In the technique for this two ways were presented to control the initial startup form when an application is launched. There's a specific reason why we did this: you need to choose the option that best fits your application.

The first option is simply going to your application entry point, the Main function, and changing the code that creates and displays your initial Windows Form. If you know that the initial form will not change often, then this is the best route to take.

The second option lets you set the initial form by changing a property in the project's property pages. You might be thinking, why would I ever want to do this? One advantage is that you open the possibility of using automation tools for user-interface validation. You could theoretically create a tool that enumerates the forms within a project and changes the StartupObject property to each one of those forms. An additional advantage is being able to specify different forms for either debug or release mode. For instance, you could create a form that captures debug trace information from your main user-interface form while release mode simply displays the main form and bypasses the debug trace form.

 <  Day Day Up  >  


Microsoft Visual C# .Net 2003
Microsoft Visual C *. NET 2003 development skills Daquan
ISBN: 7508427505
EAN: 2147483647
Year: 2003
Pages: 440

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