Sunday, January 21, 2007

Showing a Splash Screen

Guys,
The integrated desktop sample code provided by MSDN has been extremely helpful in clarifying a lot of queries I had. Please download this and look at the source code. I had a hard time trying to compile this app and I haven't run it yet because of some missing references to some assemblies, but the code itself is quite helpful for beginners like me.
Check this link out:
http://msdn.microsoft.com//msdnmag/issues/06/09/SmartClients/default.aspx

So from this code, I see how easy it is to create a splash screen. You just need to create a regular form, make it look like your Splash Screen and then add a timer to it to close it after the time interval expires. Here's the code for the Timer_Tick event:

private void splashTimer_Tick(object sender, EventArgs e)
{
if (InvokeRequired)
{
Invoke(new EventHandler(splashTimer_Tick), e);
}
else
{
Close();
}
}

The splash screen can then be invoked from within the Shell application by overriding the BeforeShellCreated method as shown:

base.BeforeShellCreated();
Thread th = new Thread(new ThreadStart(DoSplash));
th.Start();

The DoSplash then creates the form as shown:

private static void DoSplash()
{
Splash sp = new Splash();
sp.ShowDialog();

}

As simple as that.

No comments: