• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 231
  • Last Modified:

The lowdown on using a progress bar

Hi,

I'm about to use my first progress bar, and I was wondering if someone could give me a quick overview of the salient points.

I just need it to count from 10 seconds down to zero, and I can make a call at each second to decrement the value.  Then, I'll reset it to 10 and start again.

Thanks,
Bob
0
ba272
Asked:
ba272
  • 2
  • 2
1 Solution
 
testnCommented:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;

namespace WindowsApplication1
{
      /// <summary>
      /// Summary description for Form1.
      /// </summary>
      public class Form1 : System.Windows.Forms.Form
      {
            private System.Windows.Forms.ProgressBar progressBar1;
            private System.Windows.Forms.Button button1;
            private System.Windows.Forms.Timer timer1;
            private System.ComponentModel.IContainer components;

            public Form1()
            {
                  //
                  // Required for Windows Form Designer support
                  //
                  InitializeComponent();

                  //
                  // TODO: Add any constructor code after InitializeComponent call
                  //
            }

            /// <summary>
            /// Clean up any resources being used.
            /// </summary>
            protected override void Dispose( bool disposing )
            {
                  if( disposing )
                  {
                        if (components != null)
                        {
                              components.Dispose();
                        }
                  }
                  base.Dispose( disposing );
            }

            #region Windows Form Designer generated code
            /// <summary>
            /// Required method for Designer support - do not modify
            /// the contents of this method with the code editor.
            /// </summary>
            private void InitializeComponent()
            {
                  this.components = new System.ComponentModel.Container();
                  this.progressBar1 = new System.Windows.Forms.ProgressBar();
                  this.button1 = new System.Windows.Forms.Button();
                  this.timer1 = new System.Windows.Forms.Timer(this.components);
                  this.SuspendLayout();
                  //
                  // progressBar1
                  //
                  this.progressBar1.Location = new System.Drawing.Point(56, 88);
                  this.progressBar1.Maximum = 10;
                  this.progressBar1.Name = "progressBar1";
                  this.progressBar1.Size = new System.Drawing.Size(184, 23);
                  this.progressBar1.Step = 1;
                  this.progressBar1.TabIndex = 0;
                  //
                  // button1
                  //
                  this.button1.Location = new System.Drawing.Point(104, 184);
                  this.button1.Name = "button1";
                  this.button1.TabIndex = 1;
                  this.button1.Text = "button1";
                  this.button1.Click += new System.EventHandler(this.button1_Click);
                  //
                  // timer1
                  //
                  this.timer1.Interval = 1000;
                  this.timer1.Tick += new System.EventHandler(this.timer1_Tick);
                  //
                  // Form1
                  //
                  this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
                  this.ClientSize = new System.Drawing.Size(292, 273);
                  this.Controls.Add(this.button1);
                  this.Controls.Add(this.progressBar1);
                  this.Name = "Form1";
                  this.Text = "Form1";
                  this.ResumeLayout(false);

            }
            #endregion

            /// <summary>
            /// The main entry point for the application.
            /// </summary>
            [STAThread]
            static void Main()
            {
                  Application.Run(new Form1());
            }

            private void button1_Click(object sender, System.EventArgs e)
            {
                  this.progressBar1.Value = 0;
                  timer1.Enabled = true;
            }

            private void timer1_Tick(object sender, System.EventArgs e)
            {
                  this.progressBar1.Value += 1;
                  this.progressBar1.Invalidate();
                  if (this.progressBar1.Value==10)
                        timer1.Enabled = false;
                  
            }
      }
}
0
 
testnCommented:
how about this example... but it's the other way around.... start from 0 and count to 10 :)

first you need a progressbar control
second you need a timer control
set interval to 1000 means that it will invoke timer1_Tick every one second (1000 milliseconds)
then inside the eventhandler, you can update the progressbar value as needed
0
 
ba272Author Commented:
Perfect!  

Thanks.
0
 
ba272Author Commented:
Sorry for the delay.  I muct have been so excited it was working that I forgot to accept it your answer.

Bob
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now