Click here to Skip to main content
15,885,985 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have an app that runs Form1 (by default). How i would like to add another form Form2 and this form must be shown first. Hot to do that?
For example Form2 will contain languages so the user must first chose language, then use the app.
Posted

In Program.cs file :

C#
Application.Run(new Form2());


instead of

C#
Application.Run(new Form1());
 
Share this answer
 
v2
Comments
Thomas Daniels 28-Aug-13 12:13pm    
Correct, +5!
phil.o 28-Aug-13 12:14pm    
Thanks :)
The answer is: in your Main method (entry point), you have something like:
C#
Application.Run(new Form1());

Replace it to Form2. This call defines what form is the main one.

However, this is not so simple. You don't explain what exactly do you want, and that could make a big difference. What happens if you show other forms? The main form is still main: when you close it, you exit the whole application. If you want this behavior on other forms, you would need to use Application.Exit. If you want to keep a main form main, and show other forms at the same time, this is not a problem.

But if your goal is to show one form at a time (a kind of a wizard behavior), you could do one of the two things: 1) repeat the code shown above in the Main method for all forms you want; in this case, you should calculate what to do next, depending on some "result" of the operation on a previous form; such "semi-sequential" scenario will be very limited anyway; 2) use only one form; in this case, what you planned to be forms should be different panels; show one panel at a time on the same form, making other panels hidden.

—SA
 
Share this answer
 
Comments
Thomas Daniels 28-Aug-13 12:17pm    
Correct, +5!
Sergey Alexandrovich Kryukov 28-Aug-13 12:20pm    
Thank you.
—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900