ProgressBar.Increment(Int32) Metodo

Definizione

Consente di avanzare la posizione corrente dell'indicatore di stato in base al valore specificato.

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

Parametri

value
Int32

Valore di incremento della posizione corrente dell'indicatore di stato.

Eccezioni

La proprietà Style è impostata su Marquee.

Esempio

Nell'esempio di codice seguente viene illustrato come usare il Increment metodo e la Value proprietà per incrementare il valore di un ProgressBar oggetto in Tick caso di .Timer L'esempio visualizza anche la Value proprietà in un StatusBarPanel per fornire una rappresentazione testuale dell'oggetto ProgressBar. In questo esempio è necessario disporre di un controllo, denominato e di un controllo che contiene un StatusBarPanelStatusBarProgressBar oggetto , denominato statusBarPanel1.progressBar1 L'oggetto Timer, denominato time, deve essere aggiunto al modulo come 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

Commenti

Il Increment metodo consente di incrementare il valore della barra di stato in base a una quantità specifica. Questo metodo di incremento della barra di stato è simile all'uso della Step proprietà con il PerformStep metodo . La Value proprietà specifica la posizione corrente dell'oggetto ProgressBar. Se, dopo aver chiamato il Increment metodo, la Value proprietà è maggiore del valore della Maximum proprietà, la Value proprietà rimane al valore della Maximum proprietà. Se, dopo aver chiamato il Increment metodo con un valore negativo specificato nel value parametro, la Value proprietà è minore del valore della proprietà, la Value proprietà rimane al valore della MinimumMinimum proprietà.

Poiché un ProgressBar oggetto il cui stile è impostato per Marquee visualizzare una barra di scorrimento continuo anziché la relativa Valuechiamata Increment non è necessaria e genererà un InvalidOperationExceptionoggetto .

Si applica a

Vedi anche