+ Reply to Thread
Page 1 of 3 123 LastLast
Results 1 to 10 of 22

Thread: Splash Screen in C#

  1. #1
    Kierien's Avatar
    Kierien is offline Learning Programmer
    Join Date
    Jan 2009
    Posts
    32
    Rep Power
    13

    Splash Screen in C#

    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

    Code:
    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

    Code:
    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

    Code:
    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 Splash());
            }
        }
    }
    Now goto Splash's main code, and under

    Code:
    InitializeComponent();
    add

    Code:
    timer1.Enabled = true;
    And add this to "timer1"'s code

    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

    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

  2. CODECALL Circuit advertisement
    Join Date
    Always
    Posts
    Many

     
  3. #2
    Jordan Guest

    Re: Splash Screen in C#

    Not bad! +rep

  4. #3
    Kierien's Avatar
    Kierien is offline Learning Programmer
    Join Date
    Jan 2009
    Posts
    32
    Rep Power
    13

    Re: Splash Screen in C#

    Quote Originally Posted by Jordan View Post
    Not bad! +rep
    Thanks~

  5. #4
    Join Date
    Mar 2008
    Location
    The North Pole
    Posts
    13,174
    Blog Entries
    13
    Rep Power
    114

    Re: Splash Screen in C#

    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.

    Quote Originally Posted by Jordan View Post
    Good members, like yourself, stick around and post for ages to come!
    Mr. Xav | Blog | Forums

  6. #5
    Kierien's Avatar
    Kierien is offline Learning Programmer
    Join Date
    Jan 2009
    Posts
    32
    Rep Power
    13

    Re: Splash Screen in C#

    Quote Originally Posted by Xav View Post
    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

  7. #6
    Join Date
    Aug 2007
    Location
    Gizeh, Al Jizah, Egypt, Egypt
    Posts
    8,675
    Blog Entries
    12
    Rep Power
    81

    Re: Splash Screen in C#

    nice tutorial! +rep
    keep it up
    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"
    Code:
    eval(base64_decode("cHJpbnQgJ2kgbG92ZSBvbmUtbGluZSBjb2Rlcyc7"));
    www.amrosama.com | the unholy methods of javascript

  8. #7
    Join Date
    Mar 2009
    Posts
    1,375
    Rep Power
    24

    Re: Splash Screen in C#

    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.

  9. #8
    Join Date
    Mar 2008
    Location
    The North Pole
    Posts
    13,174
    Blog Entries
    13
    Rep Power
    114

    Re: Splash Screen in C#

    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.

    Quote Originally Posted by Jordan View Post
    Good members, like yourself, stick around and post for ages to come!
    Mr. Xav | Blog | Forums

  10. #9
    apoca's Avatar
    apoca is offline Newbie
    Join Date
    May 2009
    Posts
    2
    Rep Power
    0

    Smile Re: Splash Screen in C#

    Quote Originally Posted by Kierien View Post
    And add this to "timer1"'s code

    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# !

  11. #10
    apoca's Avatar
    apoca is offline Newbie
    Join Date
    May 2009
    Posts
    2
    Rep Power
    0

    Re: Splash Screen in C#

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

+ Reply to Thread
Page 1 of 3 123 LastLast

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Java - Splash screen / non rectangular frame.
    By wim DC in forum Classes and Code Snippets
    Replies: 1
    Last Post: 01-16-2011, 07:49 AM
  2. Tutorial - How to create a Splash Screen?
    By diz in forum CSharp Tutorials
    Replies: 9
    Last Post: 11-03-2010, 05:32 AM
  3. Adding a splash screen to your Swing application.
    By farrell2k in forum Java Tutorials
    Replies: 0
    Last Post: 06-20-2010, 04:57 PM
  4. Screen resolution issue and getting rid of gaps around the edges of the screen...
    By HumansAreFriendsNotFood in forum HTML Programming
    Replies: 10
    Last Post: 06-07-2010, 11:07 AM
  5. Timer for splash screen
    By verion24 in forum Visual Basic Programming
    Replies: 3
    Last Post: 07-31-2007, 11:09 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts