Jump to content

Tutorial - How to create a Splash Screen?

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
9 replies to this topic

#1
diz

diz

    Newbie

  • Members
  • Pip
  • 7 posts
Hi all,

Just to share what i had just learn and hope this can be helpful to the rest

Happy Programming! :)


How to Create a Splash Screen?

Part 1 : Preparing your Screen Splash

Firstly let's start a new C# Window Form Project.

Once this is done, add a new Window Form into the Project and rename it as SplashForm.cs

This new Window Form will be your Splash Screen Window Form.

Ok time to set some properties.

Here are some basic properties you will need to edit :

From the SplashForm.cs Properties,
1. Set the StartPosition to CenterScreen,
2. Set the FormBorderStyle to None, and
3. Change the BackgroundImage to your Splash Screen image.

Now add a timer from the Toolbox,
under the timer Properties,

1. Set the Enabled to True, and
2. Set the Interval to 10000, to indicate how long in milliseconds will the Splash Screen be displayed.
3. Set the Modifers to Public

Now you have done preparing your new Splash Screen, but wait!
So how to display it before the main program start?



Part 2 : Coding your Splash Screen

Now we will need to add some code to the default code in Form1.Designer.cs.

Open your Form1.Designer.cs and code the following code below in InitializeComponent() Method

this.Load += new System.EventHandler(this.SplashScreen_Load);

This statement is to load the SplashScreen_Load Method.

Add a new Method

private void SplashScreen_Load(object sender, System.EventArgs e)

{

frmSplash.ShowDialog();

this.Show();

}

This method will display the Splash Screen First , then show the Main Form.

Declare a new assignment

public SplashForm frmSplash = new SplashForm();

This declaration is to assign frmSplash

Not over as yet!

Now we have done with how to display the Splash Screen



Part 3 : Closing a Splash Screen

we will now proceed to code how to close the Splash Screen

Now we will need to add some code to the default code in SplashForm.Designer.cs.

Add the following code into InitializeComponent() Method

this.Click += new System.EventHandler(this.SplashForm_Click);

and add 2 new methods

public void SplashForm_Click(object sender, System.EventArgs e)

{

this.close

}


public void timer1_Tick(object sender, System.EventArgs e)

{

this.close

}

So to close the Splash Screen, the two condition stated in the method will be either by mouse click on the Splash Screen Window or when the timer goes from 10000 to 0

Now you have finally created and coded your splash screen.

Press F5 and see if it works.

Hope this is proven helpful to all.

PS: This is my first guide so go easy on me :p
If there is any incorrect information please comment and i will get them corrected. Thank!





Changes Log:
1. Correction from second to milliseconds for Interval Setting for timer
2. Include a setting requirement for timer to work, setting Modifers from private to public

Edited by diz, 08 June 2009 - 07:34 PM.


#2
Guest_Jordan_*

Guest_Jordan_*
  • Guests
Very cool, diz! +rep

#3
diz

diz

    Newbie

  • Members
  • Pip
  • 7 posts

Jordan said:

Very cool, diz! +rep

Thanks a lot Jordan. :)

#4
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
+rep :) Nice job.
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#5
Vswe

Vswe

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 9,552 posts

diz said:

2. Set the Interval to 10000, to indicate how long in seconds will the Splash Screen be displayed.


You mean milliseconds. Or does it take 10000 second for it to close? :P

#6
diz

diz

    Newbie

  • Members
  • Pip
  • 7 posts

Vswe said:

You mean milliseconds. Or does it take 10000 second for it to close? :P

Opps, Good catch!

I have corrected the tutorial.

Thanks!

#7
doomsaber

doomsaber

    Newbie

  • Members
  • Pip
  • 5 posts
I tried the code, but when I attempted to add this.close in the last step, it doesn't work. I tried Close();, but that doesn't seem to work either.

#8
DMus

DMus

    Newbie

  • Members
  • Pip
  • 1 posts
Hi you should give it as, It will fix the problem


private void SplashForm_Click(object sender, EventArgs e)
{
this.Close();
}

private void timer1_Tick_1(object sender, EventArgs e)
{
this.Close();
}


Good Luck
Mahesha :thumbup1:

#9
Charny

Charny

    Learning Programmer

  • Members
  • PipPipPip
  • 53 posts
Thanks for the tutorial!! I'll add a spalsh screen in the next version of my script maker :)

#10
lgwapnitsky

lgwapnitsky

    Newbie

  • Members
  • Pip
  • 1 posts

diz said:

Hi all,

Now add a timer from the Toolbox,
under the timer Properties,

1. Set the Enabled to True, and
2. Set the Interval to 10000, to indicate how long in milliseconds will the Splash Screen be displayed.
3. Set the Modifers to Public

and add 2 new methods

public void SplashForm_Click(object sender, System.EventArgs e)

{

this.close

}


public void timer1_Tick(object sender, System.EventArgs e)

{

this.close

}

I just discovered this yesterday - great tutorial, but the timer isn't working. I've even set it down to 1000 ms with no luck. Do I have to add an event handler for timer1_Tick the same way I had to for SplashForm_Click?

Thanks,
Larry