ProgressBar.Increment 方法

按指定的数量增加进度栏的当前位置。

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

语法

声明
Public Sub Increment ( _
    value As Integer _
)
用法
Dim instance As ProgressBar
Dim value As Integer

instance.Increment(value)
public void Increment (
    int value
)
public:
void Increment (
    int value
)
public void Increment (
    int value
)
public function Increment (
    value : int
)

参数

  • value
    增加进度栏的当前位置所根据的数量。

异常

异常类型 条件

InvalidOperationException

Style 属性被设置为 Marquee

备注

Increment 方法使您可以按指定的数量增加进度栏的值。这种增加进度栏的方法类似于将 Step 属性用于 PerformStep 方法。Value 属性指定 ProgressBar 的当前位置。如果在调用 Increment 方法之后,Value 属性大于 Maximum 属性的值,则 Value 属性仍然在 Maximum 属性的值处。在 value 参数中指定负值时调用 Increment 方法之后,如果 Value 属性小于 Minimum 属性的值,则 Value 属性仍然在 Minimum 属性的值处。

示例

下面的代码示例演示如何使用 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

请参见

参考

ProgressBar 类
ProgressBar 成员
System.Windows.Forms 命名空间
Maximum
Minimum
Value
Step
PerformStep