ProgressBar.Increment(Int32) Méthode

Définition

Fait avancer la position actuelle de la barre de progression de la quantité spécifiée.

public:
 void Increment(int value);
public void Increment (int value);
member this.Increment : int -> unit
Public Sub Increment (value As Integer)

Paramètres

value
Int32

Quantité d'incrémentation de la position actuelle de la barre de progression.

Exceptions

La propriété Style est définie sur Marquee.

Exemples

L’exemple de code suivant montre comment utiliser la Increment méthode et la Value propriété pour incrémenter la valeur d’un ProgressBar dans le Tick cas d’un Timer. L’exemple affiche également la Value propriété dans un StatusBarPanel pour fournir une représentation textuelle du ProgressBar. Cet exemple nécessite que vous disposiez d’un ProgressBar contrôle nommé progressBar1et d’un StatusBar contrôle qui contient un StatusBarPanel, nommé statusBarPanel1. Le Timer, nommé time, doit être ajouté au formulaire en tant que membre.

private:
   Timer^ time;

   // Call this method from the constructor of the form.
   void InitializeMyTimer()
   {
      // Set the interval for the timer.
      time->Interval = 250;

      // Connect the Tick event of the timer to its event handler.
      time->Tick += gcnew EventHandler( this, &Form1::IncreaseProgressBar );

      // Start the timer.
      time->Start();
   }

   void IncreaseProgressBar( Object^ /*sender*/, EventArgs^ /*e*/ )
   {
      // Increment the value of the ProgressBar a value of one each time.
      progressBar1->Increment( 1 );

      // Display the textual value of the ProgressBar in the StatusBar control's first panel.
      statusBarPanel1->Text = String::Concat( progressBar1->Value, "% Completed" );

      // Determine if we have completed by comparing the value of the Value property to the Maximum value.
      if ( progressBar1->Value == progressBar1->Maximum )

      // Stop the timer.
      time->Stop();
   }
private Timer time = new Timer();

// Call this method from the constructor of the form.
private void InitializeMyTimer()
{
   // Set the interval for the timer.
   time.Interval = 250;
   // Connect the Tick event of the timer to its event handler.
   time.Tick += new EventHandler(IncreaseProgressBar);
   // Start the timer.
   time.Start();
}

private void IncreaseProgressBar(object sender, EventArgs e)
{
   // Increment the value of the ProgressBar a value of one each time.
   progressBar1.Increment(1);
   // Display the textual value of the ProgressBar in the StatusBar control's first panel.
   statusBarPanel1.Text = progressBar1.Value.ToString() + "% Completed";
   // Determine if we have completed by comparing the value of the Value property to the Maximum value.
   if (progressBar1.Value == progressBar1.Maximum)
      // Stop the timer.
      time.Stop();
}
Private time As New Timer()

' Call this method from the constructor of the form.
Private Sub InitializeMyTimer()
   ' Set the interval for the timer.
   time.Interval = 250
   ' Connect the Tick event of the timer to its event handler.
   AddHandler time.Tick, AddressOf IncreaseProgressBar
   ' Start the timer.
   time.Start()
End Sub


Private Sub IncreaseProgressBar(ByVal sender As Object, ByVal e As EventArgs)
   ' Increment the value of the ProgressBar a value of one each time.
   ProgressBar1.Increment(1)
   ' Display the textual value of the ProgressBar in the StatusBar control's first panel.
   statusBarPanel1.Text = ProgressBar1.Value.ToString() + "% Completed"
   ' Determine if we have completed by comparing the value of the Value property to the Maximum value.
   If ProgressBar1.Value = ProgressBar1.Maximum Then
      ' Stop the timer.
      time.Stop()
   End If
End Sub

Remarques

La Increment méthode vous permet d’incrémenter la valeur de la barre de progression d’un montant spécifique. Cette méthode d’incrémentation de la barre de progression est similaire à l’utilisation de la Step propriété avec la PerformStep méthode . La Value propriété spécifie la position actuelle du ProgressBar. Si, après avoir appelé la Increment méthode , la Value propriété est supérieure à la valeur de la Maximum propriété , la Value propriété reste à la valeur de la Maximum propriété . Si, après avoir appelé la Increment méthode avec une valeur négative spécifiée dans le value paramètre, la Value propriété est inférieure à la valeur de la Minimum propriété, la Value propriété reste à la valeur de la Minimum propriété .

Étant donné qu’un ProgressBar objet dont le style est défini Marquee sur affiche une barre de défilement continue au lieu de son Value, l’appel Increment n’est pas nécessaire et déclenche un InvalidOperationException.

S’applique à

Voir aussi