ProgressBar.Step 属性

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

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

语法

声明
Public Property Step As Integer
用法
Dim instance As ProgressBar
Dim value As Integer

value = instance.Step

instance.Step = value
public int Step { get; set; }
public:
property int Step {
    int get ();
    void set (int value);
}
/** @property */
public int get_Step ()

/** @property */
public void set_Step (int value)
public function get Step () : int

public function set Step (value : int)

属性值

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

备注

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

示例

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

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
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:
   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.set_Visible(true);
    // Set Minimum to 1 to represent the first file being copied.
    pBar1.set_Minimum(1);
    // Set Maximum to the total number of files to copy.
    pBar1.set_Maximum(fileNames.get_Length());
    // Set the initial value of the ProgressBar.
    pBar1.set_Value(1);
    // Set the Step property to a value of 1 to represent each file
    // being copied.
    pBar1.set_Step(1);
    // Loop through all files to copy.
    for (int x = 1; x <= fileNames.get_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();
        }
    }
} //CopyWithProgress

平台

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 命名空间
PerformStep
Value
Increment