ProgressBar.Value 属性

获取或设置进度栏的当前位置。

**命名空间:**System.Windows.Forms
**程序集:**System.Windows.Forms(在 system.windows.forms.dll 中)

语法

声明
<BindableAttribute(True)> _
Public Property Value As Integer
用法
Dim instance As ProgressBar
Dim value As Integer

value = instance.Value

instance.Value = value
[BindableAttribute(true)] 
public int Value { get; set; }
[BindableAttribute(true)] 
public:
property int Value {
    int get ();
    void set (int value);
}
/** @property */
public int get_Value ()

/** @property */
public void set_Value (int value)
public function get Value () : int

public function set Value (value : int)

属性值

进度栏范围内的位置。默认值为 0。

异常

异常类型 条件

ArgumentException

指定的值大于 Maximum 属性的值。

- 或 -

指定的值小于 Minimum 属性的值。

备注

Value 属性的最小和最大值由 MinimumMaximum 属性指定。此属性使您可以直接增加或减小进度栏的值。若要连贯性增加 ProgressBar 控件的值,可以将 Step 属性用于 PerformStep 方法。若要以不断变化的数量来增加进度栏,则使用 Increment 方法。

示例

下面的代码示例演示如何使用 Increment 方法和 Value 属性,在 TimerTick 事件中递增 ProgressBar 的值。此示例还显示了 StatusBarPanel 中的 Value 属性以提供 ProgressBar 的文本化表示形式。此示例要求具有一个名为 progressBar1ProgressBar 控件和一个包含 StatusBarPanel,名为 statusBarPanel1StatusBar 控件。名为 timeTimer 必须作为成员添加到该窗体中。

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
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:
   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.set_Interval(250);
    // Connect the Tick event of the timer to its event handler.
    time.add_Tick(new EventHandler(IncreaseProgressBar));
    // Start the timer.
    time.Start();
} //InitializeMyTimer

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.set_Text(progressBar1.get_Value() + "% Completed");
    // Determine if we have completed by comparing the value of the Value
    // property to the Maximum value.
    if (progressBar1.get_Value() == progressBar1.get_Maximum()) {
        // Stop the timer.
        time.Stop();
    }        
} //IncreaseProgressBar

平台

Windows 98、Windows 2000 SP4、Windows CE、Windows Millennium Edition、Windows Mobile for Pocket PC、Windows Mobile for Smartphone、Windows Server 2003、Windows XP Media Center Edition、Windows XP Professional x64 Edition、Windows XP SP2、Windows XP Starter Edition

.NET Framework 并不是对每个平台的所有版本都提供支持。有关受支持版本的列表,请参见系统要求

版本信息

.NET Framework

受以下版本支持:2.0、1.1、1.0

.NET Compact Framework

受以下版本支持:2.0、1.0

请参见

参考

ProgressBar 类
ProgressBar 成员
System.Windows.Forms 命名空间
ProgressBar.Maximum 属性
ProgressBar.Minimum 属性