ProgressBar.Increment(Int32) ProgressBar.Increment(Int32) ProgressBar.Increment(Int32) ProgressBar.Increment(Int32) Method

Definición

Avanza la posición actual de la barra de progreso en la cantidad especificada.Advances the current position of the progress bar by the specified amount.

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

Parámetros

value
Int32 Int32 Int32 Int32

Cantidad que se incrementa la posición actual de la barra de progreso.The amount by which to increment the progress bar's current position.

Excepciones

Ejemplos

En el ejemplo de código siguiente se muestra cómo Increment usar el método Value y la propiedad para incrementar el valor ProgressBar de un Tick en el evento Timerde.The following code example demonstrates how to use the Increment method and the Value property to increment the value of a ProgressBar in the Tick event of a Timer. En el ejemplo también se Value muestra la propiedad StatusBarPanel en un para proporcionar ProgressBaruna representación textual de.The example also displays the Value property in a StatusBarPanel to provide a textual representation of the ProgressBar. Este ejemplo requiere que ProgressBar tenga un control, denominado progressBar1, y un StatusBar control que contenga un StatusBarPanel, denominado statusBarPanel1.This example requires that you have a ProgressBar control, named progressBar1, and a StatusBar control that contains a StatusBarPanel, named statusBarPanel1. Timer, Denominadotime, debe agregarse al formulario como miembro.The Timer, named time, must be added to the form as a member.

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

El Increment método permite incrementar el valor de la barra de progreso en una cantidad específica.The Increment method enables you to increment the value of the progress bar by a specific amount. Este método de incrementar la barra de progreso es similar al uso de Step la propiedad con PerformStep el método.This method of incrementing the progress bar is similar to using the Step property with the PerformStep method. La Value propiedad especifica la posición actual ProgressBardel.The Value property specifies the current position of the ProgressBar. Si, después de llamar Increment al método, Value la propiedad es mayor que el valor de Maximum la propiedad, Value la propiedad permanece en el valor de Maximum la propiedad.If, after calling the Increment method, the Value property is greater than the value of the Maximum property, the Value property remains at the value of the Maximum property. Si, después de llamar Increment al método con un valor negativo especificado en value el parámetro, Value la propiedad es menor que el valor de Minimum la propiedad, Value la propiedad permanece en el valor de la Minimumpropiedad.If, after calling the Increment method with a negative value specified in the value parameter, the Value property is less than the value of the Minimum property, the Value property remains at the value of the Minimum property.

Dado que ProgressBar un objeto cuyo estilo se establece Marquee en muestra una barra de desplazamiento continuamente en lugar de Valuesu, Increment no es necesario llamar a y InvalidOperationExceptiongenerará una.Because a ProgressBar object whose style is set to Marquee displays a continuously scrolling bar instead of its Value, calling Increment is unnecessary and will raise an InvalidOperationException.

Se aplica a

Consulte también: