Click here to Skip to main content
15,886,788 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more: , +
How can we display splash screen with progress bar between two form until second form loaded in c# .net windows application?

How is it possible?

Help Me.

Thanks in Advance.

Ankit Agarwal
Software Engineer
Posted

1 solution

I designed an easy solution. I have not used Asynhcronous model. If it is needed you can use BackgroundWorker class.

My code is below.

C#
public partial class Form1 : Form
   {
       public Form1()
       {
           InitializeComponent();
       }

       private void btnOpen_Click(object sender, EventArgs e)
       {
           Form2 frm = new Form2();
       }
   }


Form2.cs

C#
public partial class Form2 : Form
    {
        Timer tmr;
        ProgressBar p;
        frmSplash f;
        public Form2()
        {
            InitializeComponent();
            tmr = new Timer();
            tmr.Interval = 1000;
            tmr.Tick += new EventHandler(tmr_Tick);
            tmr.Start();
            p = new ProgressBar();
            p.Height = 30;
            p.Width = 320;
            f = new frmSplash(p);
            f.Show();
        }

        void tmr_Tick(object sender, EventArgs e)
        {
            p.Value += 20;
            if (p.Value == 100)
            {
                tmr.Stop();
                Application.DoEvents();
                f.Hide();
                this.Show();


            }
        }
    }


And I added a WinForm named frmSplash and put a flowLayoutPanel on it. Code is below.

C#
public partial class frmSplash : Form
    {
        public frmSplash(ProgressBar prg)
        {
            InitializeComponent();
            flowLayoutPanel1.Controls.Add(prg);
        }
    }


Run Form1 and click button. First splash form will be opened after progressbar is filled it will be hide and Form2 will be displayed.

Regards,
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900