A Simple Splash screen in C#

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:

  1. Added one Form with an Image, as Splashscreen.cs, and my main UI is Welcome.cs
  2. In the Program.cs I modified the code like the following
  3. 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);
    }
    
  4. And in the Welcome.cs, added one parameterized constructor, with SplashScreen as the Parameter
  5. SplashScreen _s = null;
    public Welcome(SplashScreen s)
    {
    	InitializeComponent();
    	this._s = s;
    }
    
  6. And in the Form_Load() event I added code to close the splash screen if exists.
  7. if (this._s != null) { this._s.Close(); }
    
  8. Run the application, see the splash is coming and after that Main UI is coming
This entry was posted in .Net, .Net 3.0 / 3.5, Visual Studio, Windows Forms and tagged , , , . Bookmark the permalink.

0 Responses to A Simple Splash screen in C#

  1. You can make it as topmost window as well. Looks good while loading

  2. anuraj says:

    Thanks [:)], I didn’t tried that one. But I think it will make the debugging difficult.

  3. Vb Reader says:

    Hi true
    but if it is that much troublesoume you can use #debug to find that whether it is in debug mode and then change the topmost window to false. Should work

Leave a Reply

Your email address will not be published. Required fields are marked *

*


*

You may use these HTML tags and attributes: <a href="" title="" rel=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>