ProgressBar.Value Propriété

Définition

Obtient ou définit la position actuelle de la barre de progression.

public:
 property int Value { int get(); void set(int value); };
[System.ComponentModel.Bindable(true)]
public int Value { get; set; }
[<System.ComponentModel.Bindable(true)>]
member this.Value : int with get, set
Public Property Value As Integer

Valeur de propriété

Position dans la plage de la barre de progression. La valeur par défaut est 0.

Attributs

Exceptions

La valeur spécifiée est supérieure à la valeur de la propriété Maximum.

- ou -

La valeur spécifiée est inférieure à la valeur de la propriété Minimum.

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

Les valeurs minimales et maximales de la Value propriété sont spécifiées par les Minimum propriétés et Maximum . Cette propriété vous permet d’incrémenter ou de décrémenter directement la valeur de la barre de progression. Pour effectuer des augmentations cohérentes de la valeur du ProgressBar contrôle, vous pouvez utiliser la Step propriété avec la PerformStep méthode . Pour augmenter la valeur de la barre de progression de différentes quantités, utilisez la Increment méthode .

S’applique à

Voir aussi