What is Splash Screen?
From the Wikipedia:
"A splash screen is an image that appears while a game or program is loading." ... "Splash screens are typically used by particularly large applications to notify the user that the program is in the process of loading." ... "A splash screen disappears when the application's main window appears." ... "Since splash screens often increase the wait for the desired content and may take a long time to load, they are not liked by all users."
Examples of splash screens in SQL Server 2008 and Microsoft Excel:
Actually when a splash screen is displayed, various processes are running/starting behind the scenes. In this article we will create a simple splash screen step-by-step but we will not run or create any progress bar or load any process.
Let's Begin
1. Create a new project in Visual Studio as in the following:
2. I created a simple Hello World application (MainForm.cs) that will be shown after the splash screen.
3. Add another form that will be used as the splash screen for this project as in the following:
4. Change the Border style of the SplashSreen form to none.
5. Change the start position to the center of the screen so the splash screen displays in the center of the screen.
6. Add a PictureBox to the SplashScreen form using the toolbox. Actually I am using an image for the splash screen (you can try something different).
7. Go to the file program.cs that contains the Main() method and make sure that the program starts with the SplashScreen form.
Application.Run(new SplashScreen());
8. Go to the SplashScreen.cs for the form, click on "Events" and double-click on the "Shown" event as in the following:
9. Add this code:
//Use timer class
Timer tmr;
private void SplashScreen_Shown(object sender, EventArgs e)
{
tmr = new Timer();
//set time interval 3 sec
tmr.Interval = 3000;
//starts the timer
tmr.Start();
tmr.Tick += tmr_Tick;
}
void tmr_Tick(object sender, EventArgs e)
{
//after 3 sec stop the timer
tmr.Stop();
//display mainform
Mainform mf = new Mainform();
mf.Show();
//hide this form
this.Hide();
}
10. Go to the Events for the MainForm.cs form.
Double-click on the FormClosed Event and add this Code:
private void Mainform_FormClosed(object sender, FormClosedEventArgs e)
{
//exit application when form is closed
Application.Exit();
}
Final Preview