Compartir vía


ProgressBar.Value Propiedad

Definición

Obtiene o establece la posición actual de la barra de progreso.

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

Valor de propiedad

Posición dentro del intervalo de la barra de progreso. El valor predeterminado es 0.

Atributos

Excepciones

El valor especificado es mayor que el valor de la Maximum propiedad .

O bien

El valor especificado es menor que el valor de la Minimum propiedad .

Ejemplos

En el ejemplo de código siguiente se muestra cómo usar el Increment método y la Value propiedad para incrementar el valor de en ProgressBar caso Tick de que sea Timer. En el ejemplo también se muestra la Value propiedad de para StatusBarPanel proporcionar una representación textual de .ProgressBar En este ejemplo se requiere que tenga un ProgressBar control, denominado progressBar1, y un StatusBar control que contenga un StatusBarPanel, denominado statusBarPanel1. El Timer, denominado time, debe agregarse al formulario como miembro.

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

Comentarios

Los valores mínimo y máximo de la Value propiedad se especifican mediante las Minimum propiedades y Maximum . Esta propiedad permite incrementar o disminuir directamente el valor de la barra de progreso. Para realizar aumentos coherentes en el valor del ProgressBar control, puede usar la Step propiedad con el PerformStep método . Para aumentar el valor de la barra de progreso por diferentes cantidades, use el Increment método .

Se aplica a

Consulte también