Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to build splash screen in windows forms application?

I need to show splash screen on my application start for few seconds. Does anybody know how to implement this?

Will be much appreciate for the help.

like image 864
mironych Avatar asked Oct 31 '11 15:10

mironych


People also ask

What is splash in C#?

A splash screen usually appears while a application or program launching, it normally contains the logo of the company or sometimes some helpful information about the development. It can be an animation or image or logo or etc.

What is splash screen in application?

Starting in Android 12, the launch animation for all apps when running on a device with Android 12 or higher. This includes an into-app motion at launch, a splash screen showing your app icon, and a transition to your app itself.


1 Answers

First, create your splash screen as a borderless, immovable form with your image on it, set to initially display at the center of the screen, colored the way you want. All of this can be set from within the designer; specifically, you want to:

  • Set the form's ControlBox, MaximizeBox, MinimizeBox and ShowIcon properties to "False"
  • Set the StartPosition property to "CenterScreen"
  • Set the FormBorderStyle property to "None"
  • Set the form's MinimumSize and MaximumSize to be the same as its initial Size.

Then, you need to decide where to show it and where to dismiss it. These two tasks need to occur on opposite sides of the main startup logic of your program. This could be in your application's main() routine, or possibly in your main application form's Load handler; wherever you're creating large expensive objects, reading settings from the hard drive, and generally taking a long time to do stuff behind the scenes before the main application screen displays.

Then, all you have to do is create an instance of your form, Show() it, and keep a reference to it while you do your startup initialization. Once your main form has loaded, Close() it.

If your splash screen will have an animated image on it, the window will need to be "double-buffered" as well, and you will need to be absolutely sure that all initialization logic happens outside the GUI thread (meaning you cannot have your main loading logic in the mainform's Load handler; you'll have to create a BackgroundWorker or some other threaded routine.

like image 169
KeithS Avatar answered Sep 21 '22 01:09

KeithS