ProgressBar.Value ProgressBar.Value ProgressBar.Value ProgressBar.Value Property

定义

获取或设置进度栏的当前位置。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; }
member this.Value : int with get, set
Public Property Value As Integer

属性值

进度栏范围内的位置。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和属性在的Tick事件Timer中递增的ProgressBar值。The 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. 该示例还StatusBarPanel在中Value显示属性以提供的文本表示形式。 ProgressBarThe example also displays the Value property in a StatusBarPanel to provide a textual representation of the ProgressBar. ProgressBar示例要求您具有一个名progressBar1为的控件和StatusBarPanel一个StatusBar包含名为statusBarPanel1的控件。This 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由和Maximum属性指定。The 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.

适用于

另请参阅