Digg StumbleUpon LinkedIn YouTube Flickr Facebook Twitter RSS Reset

Création et Utilisation de ‘ProgressBar’

Créer,une,zone,texte,numérique
{filelink=15666}

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
 
public class ExempleProgressBar : Form
{
  AutoProgress status = new AutoProgress();
 
  public ExempleProgressBar()
  {
      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);
 
      Button stoper = new Button();
      stoper.Location = new System.Drawing.Point(109, 80);
      stoper.Name = "bouton";
      stoper.TabIndex = 2;
      stoper.Text = "Arrêter";
      stoper.Size = new System.Drawing.Size(90, 60);
      stoper.Click += new System.EventHandler(stoper_Click);
      //
      // ExempleProgressBar
      //
      this.AutoScaleBaseSize = new System.Drawing.Size(5, 14);
      this.ClientSize = new System.Drawing.Size(600, 194);
      this.Controls.Add(this.status);
      this.Controls.Add(stoper);
      this.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
      this.Name = "ExempleProgressBar";
      this.Text = "CSharp: Exemple de la barre de progression";
      this.ResumeLayout(false);
 
      status.Lancer();
 
  }
  private void stoper_Click(object sender, System.EventArgs e)
  {
      status.Stoper();
  }
  [STAThread]
  static void Main()
  {
    Application.EnableVisualStyles();
    Application.Run(new ExempleProgressBar());
  }
 
}
 
  public class AutoProgress : System.Windows.Forms.UserControl
    {
        internal System.Windows.Forms.ProgressBar barProgression;
        internal Timer leTimer;
        private int percentPerSecond = 5;
 
    public AutoProgress()
    {
            this.barProgression = new System.Windows.Forms.ProgressBar();
            this.leTimer = new System.Windows.Forms.Timer(new System.ComponentModel.Container());
            this.SuspendLayout();
 
            this.barProgression.Dock = System.Windows.Forms.DockStyle.Fill;
            this.barProgression.Location = new System.Drawing.Point(0, 0);
            this.barProgression.Name = "barProgression";
            this.barProgression.Size = new System.Drawing.Size(164, 42);
            this.barProgression.TabIndex = 2;
 
            this.leTimer.Tick += new System.EventHandler(this.leTimer_Tick);
 
            this.Controls.Add(this.barProgression);
            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;
      }
    }           
 
      // Lancer la Barre de progression
    public void Lancer()
    {
      barProgression.Maximum = 200;
 
      leTimer.Interval = 100;
      decimal step = Math.Round((decimal)barProgression.Maximum * PercentPerSecond / 1000);
      barProgression.Step = (int)step;
 
            barProgression.Value = 0;
            leTimer.Start();
        }
 
    // Stoper la Barre de progression
        public void Stoper()
        {
            leTimer.Stop();
            barProgression.Value = 0;
        }
 
        // Mettre Fin à la Barre de progression
        public void Arreter()
        {
            leTimer.Stop();
            barProgression.Value = barProgression.Maximum;
        }
 
        private void leTimer_Tick(object sender, EventArgs e)
        {
            barProgression.PerformStep();
            if (barProgression.Value == barProgression.Maximum)
            {
                barProgression.Value = 0;
            }
        }
  }

No comments yet.

Leave a Comment