< Day Day Up > |
TechniqueModify 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. CommentsIn 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 > |