Sunday, July 12, 2009

How to set start up object in C#.net windows application?

I have a simple C#.Net windows application containing multiple forms in it. When there is only one form at the begining of the project it is running by default. But when I have added other forms I am not getting any way to set one of the other forms as startup object. Plz help me out soon..........

How to set start up object in C#.net windows application?
This is very general problem with beginers. Suppose you want to open a New Form on Click of a Button. USe following code





private void button1_Click(object sender, EventArgs e)


{


Form f1 = new Form(); // f1 is your new form


f1.Show();


}








Relply me if it works or not and dont forger to visit http://codesbyshariq.blogpsot.com
Reply:If you are using Visual Studio 2005, open the Program.cs file and change the following line:





Application.Run(new Form1());





to





Application.Run(new YourForm());





where YourForm is the name of the form you want to open at startup.





You can also change the startup object from the Project properties window, but this would be more work than it sounds like you need. You would have to write another "Main" entry point, rather than change the one that was auto-generated for you. Its easier to just change the line above.


No comments:

Post a Comment