Share via


ProgressBar.Increment(Int32) Método

Definição

Avança a posição atual da barra de progresso na quantidade especificada.

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

O valor do incremento da posição atual da barra de progresso.

Exceções

A propriedade Style está definida como Marquee

Exemplos

O exemplo de código a seguir demonstra como usar o Increment método e a Value propriedade para incrementar o valor de um ProgressBar no caso de um Timer.Tick O exemplo também exibe a Value propriedade em um StatusBarPanel para fornecer uma representação textual do ProgressBar. Este exemplo exige que você tenha um ProgressBar controle, chamado progressBar1e um StatusBar controle que contém um StatusBarPanel, chamado statusBarPanel1. O Timer, chamado time, deve ser adicionado ao formulário como um membro.

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

Comentários

O Increment método permite incrementar o valor da barra de progresso em um valor específico. Esse método de incrementar a barra de progresso é semelhante ao uso da Step propriedade com o PerformStep método . A Value propriedade especifica a posição atual do ProgressBar. Se, depois de chamar o Increment método , a Value propriedade for maior que o valor da Maximum propriedade , a Value propriedade permanecerá no valor da Maximum propriedade . Se, depois de chamar o Increment método com um valor negativo especificado no value parâmetro , a Value propriedade for menor que o valor da Minimum propriedade , a Value propriedade permanecerá no valor da Minimum propriedade .

Como um ProgressBar objeto cujo estilo é definido como Marquee exibe uma barra de rolagem contínua em vez de seu Value, chamar Increment é desnecessário e gerará um InvalidOperationException.

Aplica-se a

Confira também