ProgressBar.Increment(Int32) Metoda

Definicja

Rozwija bieżącą pozycję paska postępu o określoną kwotę.

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

Parametry

value
Int32

Kwota, o którą ma zwiększać bieżącą pozycję paska postępu.

Wyjątki

Właściwość Style ma ustawioną wartość Marquee

Przykłady

W poniższym przykładzie kodu pokazano, jak za pomocą Increment metody i Value właściwości zwiększać wartość ProgressBar elementu w Tick przypadku Timerelementu . W przykładzie przedstawiono Value również właściwość w obiekcie , StatusBarPanel aby podać tekstową reprezentację elementu ProgressBar. W tym przykładzie jest ProgressBar wymagana kontrolka o nazwie i kontrolka zawierająca StatusBarStatusBarPanelelement o nazwie statusBarPanel1progressBar1. Element Timer, o nazwie time, należy dodać do formularza jako element członkowski.

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

Uwagi

Metoda Increment umożliwia zwiększanie wartości paska postępu o określoną kwotę. Ta metoda przyrostowania paska postępu jest podobna do używania Step właściwości z PerformStep metodą . Właściwość Value określa bieżącą pozycję elementu ProgressBar. Jeśli po wywołaniu Increment metody Value właściwość jest większa niż wartość Maximum właściwości, Value właściwość pozostaje na wartości Maximum właściwości . Jeśli po wywołaniu Increment metody z wartością ujemną określoną w parametrze Valuevalue właściwość jest mniejsza niż wartość Minimum właściwości, Value właściwość pozostaje na wartości Minimum właściwości.

ProgressBar Ponieważ obiekt, którego styl jest ustawiony na Marquee wyświetlanie stale przewijania paska zamiast jego Value, wywołanie Increment jest niepotrzebne i zgłosi InvalidOperationExceptionwartość .

Dotyczy

Zobacz też