Menu

Visual Studio-Style Splash Screen in Windows Forms

March 6, 2015 - Programming

Splash Screens have been a staple of Applications for decades now. Effectively they came about because as applications got larger and got longer startup times, the time from starting your application to actually seeing some indicator that it was loading was getting longer. Splash Screens are effectively an applications way of saying “Ten-four, I read you loud and clear and am loading up, just give me a moment to gather my thoughts”

Naturally, they have gone through many iterations. The most recent one that I’ve found myself quite fond of is the Splash Screen used in Visual Studio 2012 and later. This splash screen looks very similar to it’s Install screen and certainly strives for a simple appearance, inspired partly by Windows 8’s Modern UI Stylings. It has a professional, clean look that I think makes the splash screen look nice.

Splash Screen of Visual Studio 2013

Splash Screen of Visual Studio 2013

Thankfully, it’s fairly straightforward to create an equivalent-looking splash screen for your own application. Let’s create a general-purpose form that can be re-used or even compiled into a separate assembly for general purpose usage.

One downside to my coverage here is that I’m not creating it in WPF. This is primarily because I don’t like working with WPF because then I find cool stuff and then cannot use it in my normal work because we use Windows Forms!

When approximating a UI in Windows Forms, I generally get a screenshot and then add elements over top of the screenshot to match up the locations, then delete the background image. Once that is setup, we “merely” need to add all the standard Splash screen logic we might otherwise add.

There are a lot of “Splash screen” implementations that act somewhat silly, IMO; many of them, for example, will load the splash screen, then load the main window, and then close. Others will load, delay a few seconds, close, and then open the main window. These work as splash screens but my preference is to have the splash screen also double as a way to track the loading progress, so you can see how close it is to loading. This can be invaluable for your large applications that have a long initialization or which connect to an external database to track the program’s current progress during load. This is also useful if the program refuses to start for a client in trying to track down the problem without wasting too much of your or the client’s time.

My approach for a splash screen is to make it as general as possible. We have initialization code, and we have “after” initialization code. The initialization code accepts a callback which can track progress by calling interface methods which the splash screen reflects in a progress bar and progress messages. When that methods returns, the splash screen closes, and then the “after load” callback function is called.

Here is an example of my Splash Screen being inserted into the standard, blank Windows Forms application:

It constructs an informational class which contains the launch information, passes it to a new SplashScreen instance, and then shows the splash screen, which takes it from there. LoadAction is a “simulation” of a longer running task by emulating a longer task, showing the % completion as it does so. When that method returns, the splash screen closes, and runs the AfterInvocation method, which as we can see in the informational class construction call, we have being run on a separate thread.

The full source for the quick sample program can be found here: Visual Studio Splash Screen for Windows Forms

Have something to say about this post? Comment!