I was reading some articles on creating splash screens, and they all either required long codes, or had to load the application before the splash screen appeared. Therefore, I made my own method of creating a splash screen. Since I'm only a high school student, I lack programming experience, and this article should be easy to follow through. This is also my first article, so some parts might not be as good :).
Using the code
First, create a new solution with a Windows form. Add another form to the project called "Splash Screen.cs". Now, go to Program.cs (or where the main entry point is) and add:
Go to Splash Screen.cs in the Designer, set the
false. Now, add a
PictureBox. Set the
StretchImage, and the
Image to the screen you want. Set
Fill, and resize the form at will.
Next, add the components to the splash screen. Add a
FileSystemWatcher and two
Timers. Name one
timer_run and the other
timer. For the watcher, add a
Deleted event, and add
Tick events for both timers. At the same time, add a
Load event for the
Switch to the code. After the call to
watcher.Path = Application.StartupPath;
Load event, add:
if (!System.IO.File.Exists(Application.StartupPath + "\\status.tmp"))
using (System.IO.StreamWriter sw = System.IO.File.CreateText(
Application.StartupPath + "\\status.tmp"))
timer_run.Enabled = true;
This will create a file which the watcher will keep track of. In case something goes wrong, it will hide the splash screen. At the end, it enables
timer_run to start the form.
timer_run_Tick, add the following code:
timer_run.Enabled = false;
Form1 form1 = new Form1();
This will run
timer.Enabled = true;
This will close the form when
Form1 has loaded.
Create a global variable called
private double transparency = 1;
if (transparency > 0)
this.Opacity = transparency;
transparency -= 0.01;
timer.Enabled = false;
This will make the splash screen fade away when loaded.
Form1 code view. Before
InitializeComponent(), add some redundant code to slow it down and allow time for the splash screen.
int number = 0;
for (int i = 0; i < 2147483647; i++)
if (System.IO.File.Exists(Application.StartupPath + "\\status.tmp"))
System.IO.File.Delete(Application.StartupPath + "\\status.tmp");
This will delete the file and raise the event on the splash screen.
this.Hide() was used earlier,
Application.Exit() is needed, or else the splash screen will still be running.
That's it! Easy. isn't it :P?
- June 8, 2008: First release.