Splash Screen for Windows Forms Application

Splash screens are commonly used in Windows Forms applications as a way to give rapid feedback to the user while the rest of the application loads, more specifically, its main form.

Implementing the loading of other components in the background, specially UI related components, while at the same time displaying a splash screen is something easy to get wrong.

However, if you don’t mind adding a reference to Microsoft.VisualBasic, a simpler solution is available. Check example below.

using System;
using System.Windows.Forms;
using Microsoft.VisualBasic.ApplicationServices;

internal class ExampleApp : WindowsFormsApplicationBase
{
    protected override void OnCreateSplashScreen()
    {
        // Custom splash screen
        this.SplashScreen = new SplashScreen();
    }

    protected override void OnCreateMainForm()
    {
        // Time consuming startup operations go here

        // Application main form
        this.MainForm = new MainForm();
    }
}

internal static class Program
{
    [STAThread]
    static void Main()
    {
        Application.EnableVisualStyles();
        Application.SetCompatibleTextRenderingDefault(false);

        var application = new ExampleApp();

        application.MinimumSplashScreenDisplayTime = 1500;
        application.Run(Environment.GetCommandLineArgs());
    }
}
Advertisements

3 thoughts on “Splash Screen for Windows Forms Application”

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s