Hello guys. I have two forms. First form, which appear when you enter in the program, it's like a Form Intro ... ( like in C# when you enter in C# a form appear for some seconds, which there is written intro etc. ). Ok, and after 8 seconds, my first form dissapears, and a new form appears. If i close the second form, the first form remain opened.

After that 8 seconds, i tryed to put Close() / this.Close(), but the whole program is closing. So i want like after 8 seconds the first form to be closed, not just Hide.

If you look at your Program.cs file, you'll find code that looks like this:

static class Program {
    [STAThread]
    static void Main() {
        Application.EnableVisualStyles();
        Application.SetCompatibleTextRenderingDefault(false);
        Application.Run(new Form1());
    }
}

Your problem stems from that last line where it runs the form. When the first form is closed, then the Aplication.Run() is completed. One way around this is to add a second Application.Run() line for your second form. You'll have to code the first form to close itself after 8 seconds but it seems like you have most of that done already.

So, what I must to do ?

From my post "add a second Application.Run() line for your second form."

This doesn't works ... i recive an error ... so !?

Could you possibly post the code that you added, the error message you received, and which line the system indicated that the error was in? I can't see your computer screen from here.

Hello guys. I have two forms. First form, which appear when you enter in the program, it's like a Form Intro ... ( like in C# when you enter in C# a form appear for some seconds, which there is written intro etc. ). Ok, and after 8 seconds, my first form dissapears, and a new form appears. If i close the second form, the first form remain opened.

After that 8 seconds, i tryed to put Close() / this.Close(), but the whole program is closing. So i want like after 8 seconds the first form to be closed, not just Hide.

Hi, you can see the problem in a different way.
You can view the "second" form like first.
Example :

Form f = new Form(); //The first, 8 second
            f.Text = "This form life is 8 seconds";
            f.Show();
            Thread.Sleep(8000);
            f.Close();
            //This is your function at the program's beginning
            //after that the main form will appear

The problem, is because i used the Timer function ...

Can you please post the solution?!

Another way to enable closing the initial form is to use some VB behind the scenes magic (i.e. use WindowsFormsApplicationBase).

This MSDN thread shows you how.
If you change ShutdownStyle to AfterAllFormsClose it works a treat.:)

Note: The code is instead of that in Program.cs file and you will need to reset the startup object in the application propeties.
I also advise putting the code inside an additional Namespace block for the application. Then your forms can access the application using My.App.MainApp.

[Edit]The WindowsFormsApplicationBase also has a OnCreateSplashScreen override that shows the SplashScreen form for a short time before starting the main application.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.