ProgressBar.Value 屬性

定義

取得或設定進度列的目前位置。Gets or sets the current position of the progress bar.

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

屬性值

Int32

進度列範圍內的位置。The position within the range of the progress bar. 預設值是 0。The default is 0.

屬性

例外狀況

指定值大於 Maximum 屬性的數值。The value specified is greater than the value of the Maximum property.

-或--or- 指定值小於 Minimum 屬性的數值。The value specified is less than the value of the Minimum property.

範例

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

備註

屬性的最小值和最大值 Value 是由 Minimum 和屬性所指定 MaximumThe minimum and maximum values of the Value property are specified by the Minimum and Maximum properties. 這個屬性可讓您直接遞增或遞減進度列的值。This property enables you to increment or decrement the value of the progress bar directly. 若要在控制項的值中執行一致的增加 ProgressBar ,您可以將 Step 屬性與 PerformStep 方法搭配使用。To perform consistent increases in the value of the ProgressBar control you can use the Step property with the PerformStep method. 若要以不同的數量來增加進度列值,請使用 Increment 方法。To increase the progress bar value by varying amounts, use the Increment method.

適用於

另請參閱