Display a WinForms Splash Screen
by Juval Löwy
April 2003 Issue
Technology Toolbox: C#
Q: Display a WinForms Splash Screen
My application takes a while to start up. I want to display a splash screen (as Visual Studio .NET and Office applications do) while the application continues loading in the background. The toolbox has no such control. How do I implement it?
A:
The code accompanying this column contains the SplashScreen class:
public class SplashScreen
{
public SplashScreen(Bitmap splash);
public void Close();
}
SplashScreen's constructor accepts the bitmap to display. The Close method closes the splash screen. You typically use SplashScreen in the method that handles your form's Load event (see the resulting splash screen in Figure 1):
private void OnLoad(object
sender,EventArgs e)
{
Bitmap splashImage;
splashImage = new
Bitmap("Splash.bmp");
SplashScreen splashScreen;
splashScreen = new
SplashScreen(splashImage);
//Do some lengthy operations, then:
splashScreen.Close();
Activate();
}
After you close the splash screen, you activate your form in order to bring it to the foreground and give it focus.
Back to top
|