Saturday, May 10, 2014

Splash Screen for Windows Form Application using C#

Open Visual Studio.
File-->New Project.
In the dialog box, choose windows forms application.
Form1.cs design page will be open.
After that design a form listed below:

Add another form that will be used as the splash screen for this project. And name it as SplashScreen.cs .

Go to the properties of SplashScreen.cs and Change the FormBorderStyle to None. As well as change StartPosition to CenterScreen.

Now add PictureBox to SplashScreen form and add picture in the PictureBox as below :
Go to the file program.cs that contains the Main() method and make sure that the program starts with the SplashScreen form. Like :-

Application.Run(new SplashScreen());

Go to the SplashScreen form, click on "Events" and double-click on the "Shown" event.


Now add this Code there :-

public partial class SplashScreen : Form
    {
        Timer t;

        public SplashScreen()
        {
            InitializeComponent();
        }

        private void SplashScreen_Shown(object sender, EventArgs e)
        {
            t = new Timer();
            t.Interval=5000;
            t.Start();
            t.Tick += Tick1;
        }

        void Tick1(object sender, EventArgs e)
        {
            t.Stop();
            
            Form1 f = new Form1();
            f.Show();
            this.Hide();
        }
    }

Now save all files and run the project... :)

Note :- "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."

No comments:

Post a Comment