Friday, September 10, 2010

C# Tutorial: Create a Simple Splash Screen [with ProgressBar]

Here is the code

////////////// Form1 //////////////////////////////////////
// We start Form2 on its own thread. By doing that we can run Form1 and Form2 in parallel.
Thread t = new Thread(new ThreadStart(SplashScreen));
t.Start();  
// Form1 is delayed by 5 sec so the SplashScreen has time to fully load its progressbar.
Thread.Sleep(5000);
// Add this after InitializeComponent();
// After Form1 is loaded the SplashScreen's thread is terminated.
t.Abort();

////////// SplashScreen Function /////////
Application.Run(new Form2());

//////// Form2 Timer //////////////////////////////
progressBar1.Increment(1);
if (progressBar1.Value == 100) timer1.Stop();

Or download the solution

More about Threads

3 comments: