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.Design Patterns
8.Development Class
9.Event
10.File Stream
11.Generics
12.GUI Windows Form
13.Language Basics
14.LINQ
15.Network
16.Office
17.Reflection
18.Regular Expressions
19.Security
20.Services Event
21.Thread
22.Web Services
23.Windows
24.Windows Presentation Foundation
25.XML
26.XML LINQ
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source
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
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.