Michael Johnson
Michael Johnson

Reputation:

C#: What is the ideal method of adding a splash screen to a project?

I'm going to input a splash screen to an application I'm currently working on that only consists of one form which we will call frmMain for now. I want to implement a splash screen (frmSplash) but need advice as to what would be the best way to implement it. The purpose of the splash screen will be to load necessary settings into textboxes, checkboxes, etc. based on the last settings of when the program was last closed. Here's my question.

Should I let the main form load, but keep it invisible to the user and then call the splash screen which will run and then load all the settings into the main form?

If so how would I do the above? Load the frmSplash in the frmMain_Load event? I plan to keep the splash screen visible for at least 3 seconds. How would I give it the pause effect so that it stays up for 3 seconds while it recovers the settings from the settings file?

Upvotes: 4

Views: 2537

Answers (5)

TheHolyTerrah
TheHolyTerrah

Reputation: 2879

Here's a canned version you can try: Autorun Action Splash

Upvotes: 1

Mike
Mike

Reputation: 4600

There's an example here, and one with better explanations here.

Note that neither of these examples perform any kind of "pre-loading", but you can do all that in the main thread while the splash thread is doing its eye-candy work.

Hopefully this is the kind of thing you're looking for. Good luck!

Upvotes: 1

dommer
dommer

Reputation: 19820

It's probably cleaner not to load the settings in the splash form, but to keep that just for display. Display the splash form and load the settings in the main form.

Upvotes: 3

Samuel
Samuel

Reputation: 38366

I would suggest going the other way. Have frmSplash start up, parse the settings and pass them on to a new hidden frmMain. And once frmMain has finished loading (or after 3 seconds) show it.

Or just have the splash screen create a hidden frmMain and show it once it's done loading and in a valid state.

Upvotes: 1

Andrew Hare
Andrew Hare

Reputation: 351758

Yes, it is a good practice to use a splash screen to hide form initialization. Here is a pretty good tutorial that should get you up and running:

Creating a Splash Screen in C#

Upvotes: 4

Related Questions