ProgressBar.Step 属性

定义

获取或设置调用 PerformStep() 方法增加进度栏的当前位置时所根据的数量。

public:
 property int Step { int get(); void set(int value); };
public int Step { get; set; }
member this.Step : int with get, set
Public Property Step As Integer

属性值

每次调用 PerformStep() 方法增加进度栏时所根据的数量。 默认值为 10。

示例

下面的代码示例使用 控件 ProgressBar 来显示文件复制操作的进度。 该示例使用 MinimumMaximum 属性为 ProgressBar 指定等效于要复制的文件数的范围。 代码还将 Step 属性与 方法结合使用 PerformStep ,以在复制文件时递增 的值 ProgressBar 。 此示例要求创建一个名为 ProgressBarpBar1 的控件,该控件是在 中创建的 Form,并且有一个名为 CopyFile (创建的方法,该方法返回一个布尔值,指示文件复制操作已成功完成) 执行文件复制操作。 该代码还要求创建包含要复制的文件的字符串数组并将其传递给 CopyWithProgress 示例中定义的 方法,并且从 中的 Form另一个方法或事件调用 该方法。

private:
   void CopyWithProgress( array<String^>^filenames )
   {
      // Display the ProgressBar control.
      pBar1->Visible = true;

      // Set Minimum to 1 to represent the first file being copied.
      pBar1->Minimum = 1;

      // Set Maximum to the total number of files to copy.
      pBar1->Maximum = filenames->Length;

      // Set the initial value of the ProgressBar.
      pBar1->Value = 1;

      // Set the Step property to a value of 1 to represent each file being copied.
      pBar1->Step = 1;

      // Loop through all files to copy.
      for ( int x = 1; x <= filenames->Length; x++ )
      {
         // Copy the file and increment the ProgressBar if successful.
         if ( CopyFile( filenames[ x - 1 ] ) == true )
         {
            // Perform the increment on the ProgressBar.
            pBar1->PerformStep();
         }
      }
   }
private void CopyWithProgress(string[] filenames)
{
    // Display the ProgressBar control.
    pBar1.Visible = true;
    // Set Minimum to 1 to represent the first file being copied.
    pBar1.Minimum = 1;
    // Set Maximum to the total number of files to copy.
    pBar1.Maximum = filenames.Length;
    // Set the initial value of the ProgressBar.
    pBar1.Value = 1;
    // Set the Step property to a value of 1 to represent each file being copied.
    pBar1.Step = 1;
    
    // Loop through all files to copy.
    for (int x = 1; x <= filenames.Length; x++)
    {
        // Copy the file and increment the ProgressBar if successful.
        if(CopyFile(filenames[x-1]) == true)
        {
            // Perform the increment on the ProgressBar.
            pBar1.PerformStep();
        }
    }
}
Private Sub CopyWithProgress(ByVal ParamArray filenames As String())
    ' Display the ProgressBar control.
    pBar1.Visible = True
    ' Set Minimum to 1 to represent the first file being copied.
    pBar1.Minimum = 1
    ' Set Maximum to the total number of files to copy.
    pBar1.Maximum = filenames.Length
    ' Set the initial value of the ProgressBar.
    pBar1.Value = 1
    ' Set the Step property to a value of 1 to represent each file being copied.
    pBar1.Step = 1

    ' Loop through all files to copy.
    Dim x As Integer
    for x = 1 To filenames.Length - 1
        ' Copy the file and increment the ProgressBar if successful.
        If CopyFile(filenames(x - 1)) = True Then
            ' Perform the increment on the ProgressBar.
            pBar1.PerformStep()
        End If
    Next x
End Sub

注解

可以使用 Step 属性指定操作中每个已完成任务更改进度栏值的金额。 例如,如果要复制一组文件,则可能需要将 属性的值 Step 设置为 1,将 属性的值 Maximum 设置为要复制的文件总数。 复制每个文件时,可以调用 PerformStep 方法以按 属性的值 Step 递增进度栏。 如果想要更灵活地控制进度栏的值,可以使用 Increment 方法或直接设置 属性的值 Value

适用于

另请参阅