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

增加进度栏的当前位置所根据的数量。

例外

示例

下面的代码示例演示如何使用 Increment 方法和 属性在 Tick 发生 时Timer递增 的值ProgressBarValue。 该示例还显示 Value 中的 StatusBarPanel 属性,以提供 的文本表示形式 ProgressBar。 此示例要求有一个名为 ProgressBarprogressBar1控件和一个 StatusBar 包含 StatusBarPanel名为 的 statusBarPanel1控件。 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属性小于属性的值Minimum,则Value属性将保持为 属性的值Minimumvalue

ProgressBar因为样式设置为Marquee显示连续滚动条而不是其 Value的对象,因此不需要调用 Increment ,并且将引发 InvalidOperationException

适用于

另请参阅