Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I build a splash screen into a Windows Forms application without setting timers etc?

I want to show a splash screen while my application's main form is loading and the splash form should disappear without me having to build in timers etc. Another important thing is that the main form should be the one determining when the application exits, when I use my splash form to start the application and then use it to open my main form I cannot dispose the splash screen, since that will kill the application.

like image 607
Veldmuis Avatar asked Jan 19 '23 09:01

Veldmuis


1 Answers

using Microsoft.VisualBasic.ApplicationServices;

public class Startup : WindowsFormsApplicationBase
{
    protected override void OnCreateSplashScreen()
    {
        SplashScreen = new SplashForm();
    }

    protected override void OnCreateMainForm()
    {
        MainForm = new MyMainForm();
    }
}

static class Program
{
    static void Main(string[] args)
    {
        Application.EnableVisualStyles();
        Application.SetCompatibleTextRenderingDefault(false);
        new Startup().Run(args);
    }
}
like image 141
Veldmuis Avatar answered Jan 29 '23 20:01

Veldmuis