views:

932

answers:

2

I'm using System.Windows.SplashScreen to add a splash screen to my WinForms app (it has a lot of WPF controls, but the 'main window' is still a System.Windows.Forms.Form object). When the splash screen closes the whole app goes as well.

Can I stop it taking the whole app with it?

A: 

I was a bit too quick with that question - it looks like the problem here was down to how I was starting to app. If you do:

form.ShowDialog();

Then the form's parent gets set to the splash screen, so when that closes it also closes the child window (in this case 'form'), but if you use:

System.Windows.Forms.Application.Run(form)

to start the app, then 'form' is not a child of the splash screen so doesn't close with the splash screen.

Wilka
+1  A: 

Yep, it is important to do the Application.Run call. That call transfers control of your program to the whatever main form you specify. The program will then remain running until that form is closed. If you don't make that call then the Main() function retains control and the application will exit when Main() exits. This is done behind the scenes by the VB.NET IDE although it can be overridden in the application settings window on the Application tab where you can specify the startup form. In C# this code is typically added by the code template if you specify a Windows Form project, but you wont see it if you open a blank project. Hope that helps.

Steve Massing