ProgressBar.Increment(Int32) 方法

定義

以指定的數量來前移進度列的目前位置。Advances the current position of the progress bar by the specified amount.

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

參數

value
Int32

用來遞增進度列目前位置的依據數量。The amount by which to increment the progress bar's current position.

例外狀況

Style 屬性會設定為 MarqueeThe Style property is set to Marquee

範例

下列程式碼範例示範如何使用 Increment 方法和 Value 屬性,在的事件中遞增的值 ProgressBar Tick TimerThe following code example demonstrates how to use the Increment method and the Value property to increment the value of a ProgressBar in the Tick event of a Timer. 此範例也會 Value 在中顯示內容, StatusBarPanel 以提供的文字標記法 ProgressBarThe example also displays the Value property in a StatusBarPanel to provide a textual representation of the ProgressBar. 此範例需要您擁有 ProgressBar 名為的控制項, progressBar1 以及 StatusBar 包含名為的控制項 StatusBarPanel statusBarPanel1This example requires that you have a ProgressBar control, named progressBar1, and a StatusBar control that contains a StatusBarPanel, named statusBarPanel1. Timer必須將命名為的, time 以成員的形式加入至表單。The Timer, named time, must be added to the form as a member.

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方法可讓您以特定數量遞增進度列的值。The Increment method enables you to increment the value of the progress bar by a specific amount. 這種遞增進度列的方法類似于搭配使用 Step 屬性與 PerformStep 方法。This method of incrementing the progress bar is similar to using the Step property with the PerformStep method. Value屬性會指定目前的位置 ProgressBarThe Value property specifies the current position of the ProgressBar. 如果在呼叫方法之後 IncrementValue 屬性大於屬性的值 Maximum ,則 Value 屬性會維持在屬性的值 MaximumIf, after calling the Increment method, the Value property is greater than the value of the Maximum property, the Value property remains at the value of the Maximum property. 如果在 Increment 使用參數中指定的負值呼叫方法之後,屬性 value Value 會小於屬性的值 Minimum ,則 Value 屬性會維持在屬性的值 MinimumIf, after calling the Increment method with a negative value specified in the value parameter, the Value property is less than the value of the Minimum property, the Value property remains at the value of the Minimum property.

因為 ProgressBar 其樣式設定為 Marquee 顯示持續捲軸(而非其)的物件 Value ,所以不需要呼叫, Increment 並且會引發 InvalidOperationExceptionBecause a ProgressBar object whose style is set to Marquee displays a continuously scrolling bar instead of its Value, calling Increment is unnecessary and will raise an InvalidOperationException.

適用於

另請參閱