共用方式為


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 方法和 Value 屬性,在 的 事件 TimerTick 遞增 ProgressBar 的值。 此範例也會在 中 StatusBarPanel 顯示 Value 屬性,以提供 的 ProgressBar 文字表示。 此範例會要求您擁有 ProgressBar 名為 progressBar1 的控制項,以及 StatusBar 包含 StatusBarPanel 名為 的 statusBarPanel1 控制項。 名為 timeTimer ,必須新增至表單做為成員。

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

適用於

另請參閱