Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
- - - - -

Splash Screen in C#

timer

  • Please log in to reply
25 replies to this topic

#1 Kierien

Kierien

    CC Regular

  • Member
  • PipPipPip
  • 30 posts

Posted 31 January 2009 - 10:40 AM

Hi again,

As usual i'll try to keep my code as simple as possible, but just as good i hope =)

Will add screenies later.

First create a new C# project by going to

File>New>C#>Windows Form Application

Now add a new form by right clicking on the project in the solution explorer, and add a new "Windows Form" called "Splash".

Now add a timer on the "Splash" form, with its interval set at 3000. You can change that at the timer's Properties.

Now you're gonna have to change your startup form, from Form1, to splash, you can achieve that by editing "Program.cs" code, from

using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;

namespace Splash_Screen
{
    static class Program
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new Form1());
        }
    }
}

To

using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;

namespace Splash_Screen
{
    static class Program
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new [COLOR="Red"]Splash[/COLOR]());
        }
    }
}

Now goto Splash's main code, and under

InitializeComponent();

add

timer1.Enabled = true;

And add this to "timer1"'s code

Form1 MainForm = new Form1;
MainForm.Show;
timer1.Enabled = false;
this.Dispose(false);

Go back to Form1 now, and click the "Events" button (Looks like a lightning icon), and scroll down to "FormClosed", and double click it, it should bring you to the code editor. Now add this code

Application.Exit();

The reason behind this is because when Splash closes, its actually still running in the background, but just not visible, as because it is the startup form, which C# thinks is the main form, but by adding this code whenever your Form1 closes the whole application closes.

Now for the GUI =D

Set "Splash"'s "FormBorderStyle" to "Borderless", and "TopMost" to yes, and "ShowInTaskbar" to no.

Then resize your Splash form to whatever size you like, and add a picture or background, and ur done =)

Hope you found this usefull.

~kierien
  • 3

#2 Guest_Jordan_*

Guest_Jordan_*
  • Guest

Posted 31 January 2009 - 02:12 PM

Not bad! +rep
  • 0

#3 Kierien

Kierien

    CC Regular

  • Member
  • PipPipPip
  • 30 posts

Posted 31 January 2009 - 10:36 PM

Not bad! +rep


Thanks~ ;)
  • 0

#4 Xav

Xav

    CC Mentor

  • VIP Member
  • PipPipPipPipPipPipPipPip
  • 8356 posts

Posted 01 February 2009 - 04:42 AM

You can actually do all of that in the designer, without having to modify the code. The startup form can be made the first form to load in the Project Properties bit (double click it in the Solution Explorer).

It might be nice to include an option to turn off the splash, just in case it gets annoying for the user. But well done still! I can't +rep you because I +repped your other one, it won't let me.
  • 0
If you enjoy reading this discussion and are thinking about commenting, why not click here to register and start participating in under a minute?

#5 Kierien

Kierien

    CC Regular

  • Member
  • PipPipPip
  • 30 posts

Posted 01 February 2009 - 06:59 AM

You can actually do all of that in the designer, without having to modify the code. The startup form can be made the first form to load in the Project Properties bit (double click it in the Solution Explorer).

It might be nice to include an option to turn off the splash, just in case it gets annoying for the user. But well done still! I can't +rep you because I +repped your other one, it won't let me.


Ahaha no probs about rep. And yeah, i'll work on a function to disable the splash =)

~kierien
  • 0

#6 amrosama

amrosama

    CC Mentor

  • VIP Member
  • PipPipPipPipPipPipPipPip
  • 2765 posts

Posted 01 February 2009 - 07:07 AM

nice tutorial! +rep
keep it up:thumbup:
  • 0
yo homie i heard you like one-line codes so i put a one line code that evals a decrypted one line code that prints "i love one line codes"
eval(base64_decode("cHJpbnQgJ2kgbG92ZSBvbmUtbGluZSBjb2Rlcyc7"));
www.amrosama.com | the unholy methods of javascript

#7 ArekBulski

ArekBulski

    CC Devotee

  • Senior Member
  • PipPipPipPipPipPip
  • 480 posts

Posted 14 April 2009 - 04:51 PM

I totally agree with Xav. It could and maybe should be done in the designer. But the truth is: the best code is the working one. So please take this -->rep<-- from me as a sign of respect. ;)
  • 0

#8 Xav

Xav

    CC Mentor

  • VIP Member
  • PipPipPipPipPipPipPipPip
  • 8356 posts

Posted 19 April 2009 - 04:41 AM

That is false. Working code is the third best code.

The second best code is code that is fast for the coder.
The best code is code that is fast for the user.

In other words, efficient, optimised code. Therefore Kierens' code is only third best code. :)
  • 0
If you enjoy reading this discussion and are thinking about commenting, why not click here to register and start participating in under a minute?

#9 apoca

apoca

    CC Lurker

  • Just Joined
  • Pip
  • 2 posts

Posted 11 May 2009 - 09:02 PM

And add this to "timer1"'s code

Form1 MainForm = new Form1;
MainForm.Show;
timer1.Enabled = false;
this.Dispose(false);

~kierien


Hello!
I am doing my C# program with your tutorial about Splash but I dont know clearly about this quote code. Can you explain it for me,plz?
-> what is timer1's code?
-> where is it?
thank you and sorry because I'm noob in C# ^^!
  • 0

#10 apoca

apoca

    CC Lurker

  • Just Joined
  • Pip
  • 2 posts

Posted 11 May 2009 - 09:18 PM

wahh...
i had done it!
thanks u so much
+rep point :X
  • 0

#11 Guest_Jordan_*

Guest_Jordan_*
  • Guest

Posted 12 May 2009 - 06:11 AM

That is false. Working code is the third best code.

The second best code is code that is fast for the coder.
The best code is code that is fast for the user.

In other words, efficient, optimised code. Therefore Kierens' code is only third best code. :)


So you are saying:

1) Fast code that doesn't do anything is better than...
2) Code that does not work at all is better than....
3) Code that works?

I think you have that backwards because you must first have working code before you can optimize it and make it more efficient.
  • 0

#12 el_rolas

el_rolas

    CC Lurker

  • Just Joined
  • Pip
  • 1 posts

Posted 23 June 2009 - 10:05 PM

thank you

I was having troubles with the end of the application

good tutorial

and for timer1 code just double click on the timer
  • 0





Also tagged with one or more of these keywords: timer

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download