blogger counters

Friday, August 04, 2006

Creating a Splash Screen in a CAB Application

We thought about adding support in mobile CAB (Composite UI Application Block) for showing a splash screen at the very start of the application startup, but didn't get around to adding that support. I've just started working on a desktop application based on CAB, so now I'm actually a user of CAB instead of a "developer" of mobile CAB. As it turns out, it's very easy to add a splash screen.

The information below is based on a CAB application created using the Smart Client Software Factory.

Once you get beyond the most basic of CAB applications, it can take a while to load the application. Most applications have splash screens that appear as early in the process as possible and go away once the main UI appears. Here is a simple way you can do this in your own applications.

Create A new Application Class

First create a new Application generic you'll use to start your application. For example:

public abstract class SmartClientSplashApplication<TWorkItem, TShell, TSplash>
       : SmartClientApplication<TWorkItem, TShell>
   where TWorkItem : WorkItem, new()
   where TShell : Form
   where TSplash : Form, new()
{
   private TSplash _splash;

   public SmartClientSplashApplication()
   {
       _splash = new TSplash();
       _splash.Show();
   }

   protected override void AfterShellCreated()
   {
       base.AfterShellCreated();
       Shell.Activated += new EventHandler(Shell_Activated);
   }

   void Shell_Activated(object sender, EventArgs e)
   {
       Shell.Activated -= new EventHandler(Shell_Activated);
       _splash.Hide();
       _splash.Dispose();
       _splash = null;
   }
}

Create a Splash Screen

The splash screen is a form that has something on it, like a bitmap and perhaps some text, like the version number and a copyright. You can also set the border to None so you don't see the usual window. After all, it's shown while the application is loading, so you can't close it yourself.

Change Program.cs

Finally, modify the startup code in Program.cs, or ShellApplication.cs if it was generated by the Smart Client Software Factory, to use this new generic class:

class ShellApplication : SmartClientSplashApplication<WorkItem, ShellForm, SplashForm>
...      

0 Comments:

Post a Comment

<< Home