?
Solved

The lowdown on using a progress bar

Posted on 2005-03-06
4
Medium Priority
?
228 Views
Last Modified: 2010-04-16
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
Comment
Question by:ba272
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 18

Accepted Solution

by:
testn earned 2000 total points
ID: 13473601
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
 
LVL 18

Expert Comment

by:testn
ID: 13473607
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
 

Author Comment

by:ba272
ID: 13473798
Perfect!  

Thanks.
0
 

Author Comment

by:ba272
ID: 13647473
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.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…

801 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question