Here I’m going to demonstrate how to use Progress Bar, status Bar and Timer controls in C#.Net


 

Example

//creating method getTime() to get current system time.
string getTime()
        {
            string time = "";
            time = DateTime.Now.Hour.ToString() + ":" + DateTime.Now.Minute.ToString() + ":" + DateTime.Now.Second.ToString();
            return time;
        }
 
//executing progress bar at button click event.
        private void btnLoad_Click(object sender, EventArgs e)
        {           
            for (int i = progressBar1.Minimum; i <= progressBar1.Maximum; i++)
            {
//displaying ‘loading...’ in status bar
                statLabel.Text = "loading...";
                progressBar1.Increment(1);
            }           
 
            statLabel.Text = "Loading Complete";
        }
 
        private void Form2_Load(object sender, EventArgs e)
        {
//setting timer interval to 1sec
            timer1.Interval = 1000;
//enabling timer
            timer1.Enabled = true;
//seting minimun limit of progress bar
            progressBar1.Minimum = 1;
//seeting maximum limit of progress bar
            progressBar1.Maximum = 1000000;
//setting step
            progressBar1.Step = 1;           
//displating current time in label
            label1.Text = getTime();
        }
 
//updating label text every sec. to display current time at timer tick event.
        private void timer1_Tick(object sender, EventArgs e)
        {           
            label1.Text = getTime();
        }


Leave Comment