WINDOWS FORMS APPLICATION (CSWinFormSplashScreen)

Introduction

The Splash Screen sample demonstrates how to achieve splash screen effect in Windows Forms application.

Solution 1: Customized SplashScreen with "fade in" and "fade out" effect.

Solution 2: Using VB.NET Framework without "fade in" and "fade out" effect.

Running the Sample

1.       The Splash Screen fades in and then fades out.

2.       The main form shows out.

Using the Code

Solution 1: Customized SplashScreen with "fade in" and "fade out" effect.

C#
Edit|Remove
        private void ExtraFormSettings()
      {
          this.FormBorderStyle = FormBorderStyle.None;
          this.Opacity = 0.5;
          this.BackgroundImage = CSWinFormSplashScreen.Properties.Resources.SplashImage;
      }

 
C#
Edit|Remove
        void t_Tick(object sender, EventArgs e)
       {
           // Fade in by increasing the opacity of the splash to 1.0
           if (fadeIn)
           {
               if (this.Opacity < 1.0)
               {
                   this.Opacity += 0.02;
               }
               // After fadeIn complete, begin fadeOut
               else
               {
                   fadeIn = false;
                   fadeOut = true;
               }
           }
           else if (fadeOut) // Fade out by increasing the opacity of the splash to 1.0
           {
               if (this.Opacity > 0)
               {
                   this.Opacity -= 0.02;
               }
               else
               {
                   fadeOut = false;
               }
           }


           // After fadeIn and fadeOut complete, stop the timer and close this splash.
           if (!(fadeIn || fadeOut))
           {
               t.Stop();
               this.Close();
           }
       }

 

    4. Start the main form.  

Solution 2: Using VB.NET Framework without "fade in" and "fade out" effect.

   1. Add reference to "Microsoft.VisualBasic".

   2. Create a class inheriting from WindowsFormsApplicationBase.

   3. Override OnCreateSplashScreen method, and assign the SplashScreen property to an instance of the Splash form instance.

   4. Override OnCreateMainForm method, and assign the MainForm property to an instance of the main form instance.(We can keep the Splash screen for a while before set the MainForm property).

C#
Edit|Remove
  class SplashScreenUsingVBFramework : WindowsFormsApplicationBase
  {
      protected override void OnCreateSplashScreen()
      {
          base.OnCreateSplashScreen();
          // You can replace the Splash2 screen to yours.
          this.SplashScreen = new CSWinFormSplashScreen.SplashScreen2();
      }
      protected override void OnCreateMainForm()
      {
          base.OnCreateMainForm();
          //Here you can specify the MainForm you want to start.
          this.MainForm = new MainForm();
      }
  }

 

   5. In the static Main method, we can use the class deriving from WindowsFormsApplicationBase to run the application.

C#
Edit|Remove
new SplashScreenUsingVBFramework().Run(args);

 

More Information

WindowsFormsApplicationBase.SplashScreen Property