Бөлісу құралы:


ProgressBar.Increment(Int32) Метод

Определение

Перемещает текущую позицию индикатора хода выполнения по указанному количеству.

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

Параметры

value
Int32

Сумма, по которой необходимо увеличить текущую позицию индикатора хода выполнения.

Исключения

Для Style свойства задано значение Marquee

Примеры

В следующем примере кода показано, как использовать Increment метод и Value свойство для увеличения значения значения ProgressBar в Tick случае Timerсобытия. В примере также отображается Value свойство в объекте StatusBarPanel для предоставления текстового ProgressBarпредставления объекта. В этом примере требуется, чтобы у вас был ProgressBar элемент управления, именованный progressBar1и StatusBar элемент управления, содержащий именованный StatusBarPanelstatusBarPanel1элемент управления. timeИмя Timerдолжно быть добавлено в форму в качестве члена.

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

Комментарии

Метод Increment позволяет увеличить значение индикатора хода выполнения по определенному количеству. Этот метод увеличения индикатора выполнения аналогичен использованию Step свойства с методом PerformStep . Свойство Value указывает текущую позицию ProgressBarобъекта . Если после вызова Increment метода Value свойство больше значения Maximum свойства, Value свойство остается в значении Maximum свойства. Если после вызова Increment метода с отрицательным значением, указанным в value параметре, Value свойство меньше значения Minimum свойства, Value свойство остается в значении Minimum свойства.

ProgressBar Так как объект, стиль которого установлен для Marquee отображения непрерывной прокрутки, а не егоValue, вызов Increment не является ненужным и приведет к возникновениюInvalidOperationException.

Применяется к

См. также раздел