You are not connected. Please login or register

View previous topic View next topic Go down  Message [Page 1 of 1]

1 C# progress bar on Thu Aug 19, 2010 6:47 pm

Top


Contributor
Loading
It's a simple progress bar. It's useful for a fake program or something. But, it's a simple progress bar


Code:
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(12, 8);
      this.status.Name = "status";
      this.status.Size = new System.Drawing.Size(600, 20);
      //
      // Form1
      //
      this.AutoScaleBaseSize = new System.Drawing.Size(5, 14);
      this.ClientSize = new System.Drawing.Size(292, 194);
      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(0, 0);
            this.myProgressBar.Name = "myProgressBar";
            this.myProgressBar.Size = new System.Drawing.Size(164, 42);
            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(164, 42);
            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;
            }
        }
  }

2 Re: C# progress bar on Thu Aug 19, 2010 7:10 pm

Erebus

avatar
Achiever
Loading
[You must be registered and logged in to see this link.] wrote:It's a simple progress bar. It's useful for a fake program or something. But, it's a simple progress bar


Code:
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(12, 8);
      this.status.Name = "status";
      this.status.Size = new System.Drawing.Size(600, 20);
      //
      // Form1
      //
      this.AutoScaleBaseSize = new System.Drawing.Size(5, 14);
      this.ClientSize = new System.Drawing.Size(292, 194);
      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(0, 0);
            this.myProgressBar.Name = "myProgressBar";
            this.myProgressBar.Size = new System.Drawing.Size(164, 42);
            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(164, 42);
            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;
            }
        }
  }
+re'd yet again 0-0

3 Re: C# progress bar on Sat Aug 21, 2010 3:13 pm

Guest


Guest
Loading
repped you since its some long ccoding

Sponsored content


Loading

View previous topic View next topic Back to top  Message [Page 1 of 1]

Related topics

Permissions in this forum:
You cannot reply to topics in this forum