Auto progress bar : Progress Bar « Components « C# / C Sharp

Home
C# / C Sharp
1.2D Graphics
2.Class Interface
3.Collections Data Structure
4.Components
5.Data Types
6.Database ADO.net
7.Date Time
8.Design Patterns
9.Development Class
10.Event
11.File Stream
12.Generics
13.GUI Windows Form
14.Internationalization I18N
15.Language Basics
16.LINQ
17.Network
18.Office
19.Reflection
20.Regular Expressions
21.Security
22.Services Event
23.Thread
24.Web Services
25.Windows
26.Windows Presentation Foundation
27.XML
28.XML LINQ
C# / C Sharp » Components » Progress BarScreenshots 
Auto progress bar
Auto progress bar

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

public class Form1 : Form
{
  AutoProgress status = new AutoProgress();
  
  public Form1() {
      this.status = new AutoProgress();
      this.SuspendLayout();
      // 
      // status
      // 
      this.status.Location = new System.Drawing.Point(128);
      this.status.Name = "status";
      this.status.Size = new System.Drawing.Size(60020);
      // 
      // Form1
      // 
      this.AutoScaleBaseSize = new System.Drawing.Size(514);
      this.ClientSize = new System.Drawing.Size(292194);
      this.Controls.Add(this.status);
      this.Font = new System.Drawing.Font("Tahoma"8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
      this.Name = "Form1";
      this.Text = "Progress Host";
      this.ResumeLayout(false);
      
      status.Start();

  }
  [STAThread]
  static void Main()
  {
    Application.EnableVisualStyles();
    Application.Run(new Form1());
  }

}

  public class AutoProgress : System.Windows.Forms.UserControl
    {
        internal System.Windows.Forms.ProgressBar myProgressBar;
        internal Timer myTimer;
        private int percentPerSecond = 5;

    public AutoProgress()
    {
            this.myProgressBar = new System.Windows.Forms.ProgressBar();
            this.myTimer = new System.Windows.Forms.Timer(new System.ComponentModel.Container());
            this.SuspendLayout();

            this.myProgressBar.Dock = System.Windows.Forms.DockStyle.Fill;
            this.myProgressBar.Location = new System.Drawing.Point(00);
            this.myProgressBar.Name = "myProgressBar";
            this.myProgressBar.Size = new System.Drawing.Size(16442);
            this.myProgressBar.TabIndex = 2;

            this.myTimer.Tick += new System.EventHandler(this.myTimer_Tick);

            this.Controls.Add(this.myProgressBar);
            this.Name = "AutoProgress";
            this.Size = new System.Drawing.Size(16442);
            this.ResumeLayout(false);
            
    }

        public int PercentPerSecond
    {
      get {
        return percentPerSecond;
      }
      set {
                if (value < 0)
                {
                    throw new ArgumentException("Progress cannot go backward.");
                }
                else if (value == 0)
                {
                    throw new ArgumentException("Progress must go on.");
                }
                percentPerSecond = value;
      }
    }           
    
    public void Start()
    {
      myProgressBar.Maximum = 200;

      myTimer.Interval = 100;
      decimal step = Math.Round((decimal)myProgressBar.Maximum * PercentPerSecond / 1000);
      myProgressBar.Step = (int)step;

            myProgressBar.Value = 0;
            myTimer.Start();
        }

        public void Stop()
        {
            myTimer.Stop();
            myProgressBar.Value = 0;
        }

        public void Finish()
        {
            myTimer.Stop();
            myProgressBar.Value = myProgressBar.Maximum;
        }

        private void myTimer_Tick(object sender, EventArgs e)
        {
            myProgressBar.PerformStep();
            if (myProgressBar.Value == myProgressBar.Maximum)
            {
                myProgressBar.Value = 0;
            }
        }
  }


           
       
Related examples in the same category
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.