A Simple Splash screen in C#
By Anuraj P on June 12th, 2009 . No Comments .
I started my .net career in VB.Net. While developing a windows application in VB.Net it is pretty easy to put a Splash screen. There is Project property called Splash screen and you can put any form there, after that the specified form will act as a Splash screen. But when I started an windows application in C#, there is no project property called Splash screen. While doing some searching, I found lot of ways, like putting a timer and closing the splash etc. But I feel like it is not the right way of doing a splash screen, then I started my own implementation and found one. I am not sure it is good one or not, but it is working for me.
Here is the steps:
- Added one Form with an Image, as Splashscreen.cs, and my main UI is Welcome.cs
- In the Program.cs I modified the code like the following
- And in the Welcome.cs, added one parameterized constructor, with SplashScreen as the Parameter
- And in the Form_Load() event I added code to close the splash screen if exists.
- Run the application, see the splash is coming and after that Main UI is coming
static void Main()
{
Application.ApplicationExit += new EventHandler(Application_ApplicationExit);
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
SplashScreen s = new SplashScreen();
s.Show();
Welcome welcome = new Welcome(s);
Application.Run(welcome);
}
SplashScreen _s = null;
public Welcome(SplashScreen s)
{
InitializeComponent();
this._s = s;
}
if (this._s != null) { this._s.Close(); }