Click here to Skip to main content
15,895,084 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,
I have different forms in my application and I want to run a specific form at the beginning of the application how could I do it ?
I did some researches but I didn't find out.

Thank you.

What I have tried:

I tried to modify the progam.cs file by putting this
Application.Run(new Form5());
But it doesn't work.
Posted
Updated 6-Jul-16 23:51pm
Comments
BillWoodruff 7-Jul-16 6:26am    
If your goal is, as OriginalGriff shows, showing a splash screen at application start, then your problem is solved.

If your goal is to show an initial form, alone, and then, based on the user's actions, to proceed to show other Forms, or quit the Application ... for example, as in a log-in procedure ... then please revise your question to include that information, and I will respond with a different strategy, and a code example.
TatsuSheva 7-Jul-16 7:53am    
Thank you, my goal is achieved.

Yes it does.
When you use Application.Run with a form instance, it displays the form, and returns when the form is closed - so changing the form you create as pass to the method changes which form is your "main" form.
What it doesn't do is show a form and return immediately so you can display a second form.
If you are trying to show a splash screen of similar, then leave Applicatio.Run alone, and open the splash form in the contrustor of your main form using Form.Show.

If that isn't what you are trying to do, then you need to provide more information, because Applciation.Run certainly works for me!
 
Share this answer
 
Comments
TatsuSheva 7-Jul-16 5:54am    
thank you it works.
OriginalGriff 7-Jul-16 6:10am    
You're welcome!
As an idea for the future, please try to give us all the info you can as it helps us give you a better answer instead of having to guess what you mean.

Remember that we can't see your screen, access your HDD, or read your mind - we only get exactly what you type to work from!
Application.Run should be written in the Program.cs in the Main() method. Sample code given below -
C#
[STAThread]
static void Main()
{
    Application.EnableVisualStyles();
    Application.SetCompatibleTextRenderingDefault(false);
    Application.Run(new frmLogin());
}
 
Share this answer
 

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