Simple Easy C# SplashScreen with Minimal Coding (2024)

Introduction

Many applications show a splashscreen to let the user know that the program is loading and to add some flair to their program. The splashscreen typically shows the application's name, version number as well as copyright information. This approach allows the developer to use any Windows form as the splashscreen. It automatically hides the screen when the first Windows Form of the application finishes loading and is shown. Also it displays the splashscreen on exit of the application. The end result is shown below.

Simple Easy C# SplashScreen with Minimal Coding (1)

This method does not use a timer. It only shows the splashscreen while the system is loading without stalling (delaying) the loading thread and once it is loaded, the splashscreen is hidden.

Background

The approach is to use the normal startup code with only minor modifications. The splashscreen is just a plain Windows form without any special coding. There is no change to the first form of your project. The only program that is changed is the launch program named Program.cs in your project. Program.cs is a Windows generated program that is only changed when you change your top form of your project.

Using the Code

First, create a new Windows form to be your splashscreen. Set the background image of the form to be your splashscreen image. You can add labels to dynamically hold information like version, etc. Under properties for the form, set the borders to None. Its location to CenterScreen and its size to AutoSize so if you change the image, the form size is still correct. I also include a SayWelcome() and SayGoodbye() methods to show a welcome and goodbye message.

The original code in Program.cs had just a few lines and ended with:

Application.Run(new MainForm);

Comment out that line and add the new splashscreen code. First, create a static instance of the splashscreen as an attribute of the static class Program.

C#

static class Program{ // Create an instance of the splashscreen  static SplashScreen splashscreen;

Initialize the splashscreen instance in the body of the Main() method after the original Application.Run() line that we commented out. It will give you an error it you try to do it before the calls to Application.EnableVisualStyles() and Application.SetCompatibleTextRenderingDefault(false).

C#

// Initialize and show splashscreen. Say the welcome message. splashscreen = new SplashScreen();splashscreen.Show();splashscreen.SayWelcome();

Then create an instance of the top windows form. Hook into the shown and closed events. Then do the Application.Run() but this time just use the instance in place of the new MainForm.

C#

// Create an instance of MainForm and hook into shown and closed events.MainForm mainform = new MainForm();mainform.Shown += main_Shown;mainform.FormClosed += main_FormClosed;Application.Run(mainform); 

For the main_Shown() method, hide the splashscreen.

C#

static void main_Shown(object sender, EventArgs e){ // Hide the splashscreen.  splashscreen.Hide();}

For the main_FormClosed() method, hide the form being closed and show the splashscreen. I added a System.Threading.Thread.Sleep(1000) so the screen shows for a whole second before the application exits.

C#

static void main_FormClosed(object sender, FormClosedEventArgs e){ // Hide the calling form  Form form = sender as Form; form.Hide(); // Show the splash screen and say goodbye.  splashscreen.Show(); splashscreen.SayGoodBye(); System.Threading.Thread.Sleep(1000); // Pause for a second.}

That is all there is to it. The comments in the code should answer any further questions you have. Here is the complete Program.cs with the splashscreen code revisions.

C#

// Program.cs// Modified to display a SplashScreen//using System;using System.Windows.Forms;namespace WindowsAppWithSplashScreen { static class Program { // Create an instance of the splashscreen  static SplashScreen splashscreen; /// <summary>  /// The main entry point for the application.  /// </summary>  [STAThread] static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); //Application.Run(new MainForm());  //-------------- End of original lines. --------------//  // Initialize and show splashscreen. Say the welcome message.  splashscreen = new SplashScreen(); splashscreen.Show(); splashscreen.SayWelcome(); // Create an instance of MainForm and hook into shown and closed events.  MainForm main = new MainForm(); mainform.Shown += main_Shown; mainform.FormClosed += main_FormClosed; Application.Run(main); } static void main_FormClosed(object sender, FormClosedEventArgs e) { // Hide the calling form  Form form = sender as Form; form.Hide(); // Show the splash screen and say goodbye.  splashscreen.Show(); splashscreen.SayGoodBye(); System.Threading.Thread.Sleep(1000); // Pause for a second. } static void main_Shown(object sender, EventArgs e) { // Hide the splashscreen.  splashscreen.Hide(); } }}

Points of Interest

One final note: if you change the initial form name, you may have to manually edit Program.cs again. The SayWelcome() and SayGoodbye() methods are optional and can be omitted. For my application, we use Text-to-speech to have the computer say hello and goodbye for the Welcome and Goodbye. Hopefully, this is simple enough that everyone can add splash to their C# app.

History

  • Version 1.0 is the latest version.

I have been developing code in various languages for a long, long time in a plethora of languages. Currently I have been working in C# with Microsoft's Speech Technologies for Text-to-speech (TTS) and Automatic speech recognition (ASR).

Simple Easy C# SplashScreen with Minimal Coding (2024)
Top Articles
Toro Dingo For Sale Craigslist
Power Outages In Warren Michigan
Ron Martin Realty Cam
Washu Parking
East Cocalico Police Department
Voordelige mode in topkwaliteit shoppen
Free Atm For Emerald Card Near Me
Sarah F. Tebbens | people.wright.edu
Bucks County Job Requisitions
Craigslist In South Carolina - Craigslist Near You
Tap Tap Run Coupon Codes
Nation Hearing Near Me
Barstool Sports Gif
Scentsy Dashboard Log In
Aspen.sprout Forum
Curry Ford Accident Today
Bennington County Criminal Court Calendar
Xfinity Cup Race Today
Aspenx2 Newburyport
Naya Padkar Gujarati News Paper
Netwerk van %naam%, analyse van %nb_relaties% relaties
Greensboro sit-in (1960) | History, Summary, Impact, & Facts
Blackboard Login Pjc
Restaurants In Shelby Montana
Mikayla Campinos: Unveiling The Truth Behind The Leaked Content
Shiny Flower Belinda
Gesichtspflege & Gesichtscreme
L'alternativa - co*cktail Bar On The Pier
Audi Q3 | 2023 - 2024 | De Waal Autogroep
Indiana Wesleyan Transcripts
Waffle House Gift Card Cvs
Afspraak inzien
Top-ranked Wisconsin beats Marquette in front of record volleyball crowd at Fiserv Forum. What we learned.
Avance Primary Care Morrisville
Instafeet Login
Stafford Rotoworld
Sc Pick 4 Evening Archives
Omaha Steaks Lava Cake Microwave Instructions
Puretalkusa.com/Amac
Miami Vice turns 40: A look back at the iconic series
Peace Sign Drawing Reference
Southwest Airlines Departures Atlanta
Europa Universalis 4: Army Composition Guide
Caphras Calculator
Plasma Donation Greensburg Pa
Lightfoot 247
Michaelangelo's Monkey Junction
Wieting Funeral Home '' Obituaries
Mike De Beer Twitter
Gainswave Review Forum
Bunbrat
login.microsoftonline.com Reviews | scam or legit check
Latest Posts
Article information

Author: Allyn Kozey

Last Updated:

Views: 5456

Rating: 4.2 / 5 (43 voted)

Reviews: 90% of readers found this page helpful

Author information

Name: Allyn Kozey

Birthday: 1993-12-21

Address: Suite 454 40343 Larson Union, Port Melia, TX 16164

Phone: +2456904400762

Job: Investor Administrator

Hobby: Sketching, Puzzles, Pet, Mountaineering, Skydiving, Dowsing, Sports

Introduction: My name is Allyn Kozey, I am a outstanding, colorful, adventurous, encouraging, zealous, tender, helpful person who loves writing and wants to share my knowledge and understanding with you.