Thursday, January 8, 2015

Splash Screen in Windows forms using C#

10:33 PM - By azeheruddin khan 0

In this tutorial, we will go over how to create splash screen in window application using c#.

We need to add following controls on the form to achieve this functionality.

  1. Progressbar - Displaying progress on the form.
  2. Label - to display loading text.
  3. Timer - We need 2 timer controls on the form.
Need to set FormBorderStyle = None to remove border and ControlBox from the form.


using System;
using System.Windows.Forms;

namespace SplashScreen
{
    public partial class SplashForm : Form
    {
        bool flag;
        public SplashForm()
        {
            InitializeComponent();
        }      

        private void Form1_Load(object sender, EventArgs e)
        {
            flag = true;
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            if (progressBar1.Value < 99)
            {
                if (flag)
                {
                    flag = false;
                    lblLoading.Text = "Loading..";
                }
                else
                {
                    flag = true;
                    lblLoading.Text = "Loading.....";
                }
                progressBar1.Value += 25;
                if (progressBar1.Value > 50)
                {
                    timer2.Enabled = true;
                    timer2.Start();
                }
            }
            else
            {
                timer1.Stop();
                timer1.Enabled = false;
                this.Close();
            }

        }

        private void timer2_Tick(object sender, EventArgs e)
        {
            this.Opacity -= 0.06;
            if (this.Opacity <= 0)
            {
                timer2.Enabled = false;
                this.DialogResult = DialogResult.OK;
            }

        }
    }
}




You can download all the sample code from below link.



About the Author

I am Azeheruddin Khan having more than 6 year experience in c#, Asp.net and ms sql.My work comprise of medium and enterprise level projects using asp.net and other Microsoft .net technologies. Please feel free to contact me for any queries via posting comments on my blog,i will try to reply as early as possible. Follow me @fresher2programmer
View all posts by admin →

Get Updates

Subscribe to our e-mail newsletter to receive updates.

Share This Post

0 comments:

adsense

© 2014 Fresher2Programmer. WP Theme-junkie converted by Bloggertheme9
Powered by Blogger.
back to top