共用方式為


ProgressBar.Value 屬性

定義

取得或設定進度列的目前位置。

public:
 property int Value { int get(); void set(int value); };
[System.ComponentModel.Bindable(true)]
public int Value { get; set; }
[<System.ComponentModel.Bindable(true)>]
member this.Value : int with get, set
Public Property Value As Integer

屬性值

進度列範圍內的位置。 預設值是 0。

屬性

例外狀況

指定值大於 Maximum 屬性的數值。

-或-

指定值小於 Minimum 屬性的數值。

範例

下列程式碼範例示範如何使用 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

備註

屬性的 Value 最小值和最大值是由 和 Maximum 屬性所 Minimum 指定。 此屬性可讓您直接遞增或遞減進度列的值。 若要在控制項的值 ProgressBar 中執行一致的增加,您可以搭配 PerformStep 方法使用 Step 屬性。 若要依不同數量增加進度列值,請使用 Increment 方法。

適用於

另請參閱