The startup screen is a prompt box for users to wait patiently when the program starts and loads components. A good software requires a startup screen when there is a need for a startup wait. The startup screen provides users with psychological preparation to accept the slow loading of programs, and allows users to know the loading progress and content. This document is just the simplest record framework.
Create a C # Windows form application in VS2010, change the main form to FormMain, and create a form named SplashScreen. Load an image to the program as the startup screen, as shown in
Then edit the SplashScreen. cs code.
[Csharp]
/// <Summary>
/// Start Screen
/// </Summary>
Public partial class SplashScreen: Form
{
/// <Summary>
/// Start the screen itself
/// </Summary>
Static SplashScreen instance;
/// <Summary>
/// The displayed Image
/// </Summary>
Bitmap bitmap;
Public static SplashScreen Instance
{
Get
{
Return instance;
}
Set
{
Instance = value;
}
}
Public SplashScreen ()
{
InitializeComponent ();
// Set the Form Type
Const string showInfo = "Startup screen: we are trying to load the program. Please wait ...";
FormBorderStyle = FormBorderStyle. None;
StartPosition = FormStartPosition. CenterScreen;
ShowInTaskbar = false;
Bitmap = new Bitmap (Properties. Resources. SplashScreen );
ClientSize = bitmap. Size;
Using (Font font = new Font ("Les", 10 ))
{
Using (Graphics g = Graphics. FromImage (bitmap ))
{
G. DrawString (showInfo, font, Brushes. White, 130,100 );
}
}
BackgroundImage = bitmap;
}
Protected override void Dispose (bool disposing)
{
If (disposing & (components! = Null ))
{
If (bitmap! = Null)
{
Bitmap. Dispose ();
Bitmap = null;
}
Components. Dispose ();
}
Base. Dispose (disposing );
}
Public static void ShowSplashScreen ()
{
Instance = new SplashScreen ();
Instance. Show ();
}
}
/// <Summary>
/// Start Screen
/// </Summary>
Public partial class SplashScreen: Form
{
/// <Summary>
/// Start the screen itself
/// </Summary>
Static SplashScreen instance;
/// <Summary>
/// The displayed Image
/// </Summary>
Bitmap bitmap;
Public static SplashScreen Instance
{
Get
{
Return instance;
}
Set
{
Instance = value;
}
}
Public SplashScreen ()
{
InitializeComponent ();
// Set the Form Type
Const string showInfo = "Startup screen: we are trying to load the program. Please wait ...";
FormBorderStyle = FormBorderStyle. None;
StartPosition = FormStartPosition. CenterScreen;
ShowInTaskbar = false;
Bitmap = new Bitmap (Properties. Resources. SplashScreen );
ClientSize = bitmap. Size;
Using (Font font = new Font ("Les", 10 ))
{
Using (Graphics g = Graphics. FromImage (bitmap ))
{
G. DrawString (showInfo, font, Brushes. White, 130,100 );
}
}
BackgroundImage = bitmap;
}
Protected override void Dispose (bool disposing)
{
If (disposing & (components! = Null ))
{
If (bitmap! = Null)
{
Bitmap. Dispose ();
Bitmap = null;
}
Components. Dispose ();
}
Base. Dispose (disposing );
}
Public static void ShowSplashScreen ()
{
Instance = new SplashScreen ();
Instance. Show ();
}
}
And then called when the main program starts
[Csharp]
Static class Program
{
/// <Summary>
/// Main entry point of the application.
/// </Summary>
[STAThread]
Static void Main ()
{
Application. EnableVisualStyles ();
Application. SetCompatibleTextRenderingDefault (false );
// Start
SplashScreen. ShowSplashScreen ();
// Perform your own operations: Load components, load files, etc.
// The sample code is dormant for a while
System. Threading. Thread. Sleep (3000 );
// Close
If (SplashScreen. Instance! = Null)
{
SplashScreen. Instance. BeginInvoke (new MethodInvoker (SplashScreen. Instance. Dispose ));
SplashScreen. Instance = null;
}
Application. Run (new FormMain ());
}
}
Static class Program
{
/// <Summary>
/// Main entry point of the application.
/// </Summary>
[STAThread]
Static void Main ()
{
Application. EnableVisualStyles ();
Application. SetCompatibleTextRenderingDefault (false );
// Start
SplashScreen. ShowSplashScreen ();
// Perform your own operations: Load components, load files, etc.
// The sample code is dormant for a while
System. Threading. Thread. Sleep (3000 );
// Close
If (SplashScreen. Instance! = Null)
{
SplashScreen. Instance. BeginInvoke (new MethodInvoker (SplashScreen. Instance. Dispose ));
SplashScreen. Instance = null;
}
Application. Run (new FormMain ());
}
}