Click here to Skip to main content
15,920,687 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,

I'm making a project in C#.
I have a welcome screen, after pushing "next" button a new Windows-form opens. I dont seem to figure our how to automaticly close the other Windows-form that is still running in the background.

I tried some things that I've read on this forum but most of the time all my Windows-forms start closing...
Posted

Simply modify program.cs of your project, the form which you want to close is "Form1" so simply call this.Close() which closes Form1 and start Form2 automatically. There is another way as well: you can hide the first form and display second form.
C#
static void Main()
{
    Application.EnableVisualStyles();
    Application.SetCompatibleTextRenderingDefault(false);
    Application.Run(new Form1());// Form with next button
    Application.Run(new Form2());// Form to be opened when next button clicked
}
 
Share this answer
 
v3
Comments
BobJanova 3-Nov-11 11:33am    
Good answer, for a welcome screen. Note though that if you use this, nothing to do with the second form will happen until the first is closed, so if the reason you want a welcome screen is as a splash to hide a long load time, this won't work.
Xeshan Ahmed 3-Nov-11 11:47am    
thank you BobJanova
My guess is that your Welcome screen is your program's Main form, which means when you do:

this.Close();


the program stops executing, therefore closing all forms.
It's a wild guess, try posting the code where you make your welcome screen appear and what you do when you try closing it.
 
Share this answer
 
v2

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