Question : Progress Bar Bound to Timer

Using C# I need to create a simple form that contains a progress bar that moves from 0% to 100% over a fixed, linear 20 second duration.  Above the progress bar I have a label control to display a message.  At 8 seconds and again at 15 seconds I need to change the text in the label.  When the timer times out I then want to display a button which will allow the user to close the form.  Assistance to write some simple code to achieve this function is much appreciated.

Answer : Progress Bar Bound to Timer

It's not very wise to compete with Idle_Mind but I just want to propose very simple straightforward solution

Of course, there are the following controls on a form:

           this.button1
            this.progressBar1
            this.progressBar1
            this.timer1.
            this.label1
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
   public partial class Form1 : Form
    {

        public Form1()
        {
            InitializeComponent();
           
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            this.button1.Visible = false;
            this.progressBar1.Minimum = 0;
            this.progressBar1.Maximum = 200;
            this.timer1.Interval = 100;// 1 second
            this.label1.Text = "";
        }
        private void button1_Click_1(object sender, EventArgs e)
        {
            this.Close();
        }

        private void Form1_Shown(object sender, EventArgs e)
        {
            this.timer1.Start();
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            // increase progressbar
            if (this.progressBar1.Value < this.progressBar1.Maximum)
            {
                this.progressBar1.Value += 1;
            }
            // 5 seconds elapsed (25 ticks on a progre:
            if (this.progressBar1.Value  == 50)
            {
                this.label1.Text = "5 seconds";
            }
            else if (this.progressBar1.Value == 150)
            {
                this.label1.Text = "15 seconds";
            }
            else if (this.progressBar1.Value == this.progressBar1.Maximum)
            {
                this.timer1.Stop();
                this.label1.Text = "timer stopped";
                this.button1.Visible = true;
            }

        }



    }
Random Solutions  
 
programming4us programming4us