语言

ProgressBar.Maximum 属性

定义

获取或设置控件范围的最大值。

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

属性值

范围的最大值。 默认值为 100。

例外

指定的值小于 0。

示例

下面的代码示例使用控件 ProgressBar 显示文件复制操作的进度。 该示例使用 Minimum 和 Maximum 属性指定要复制的文件数的一个范围 ProgressBar 。 该代码还使用该 Step 属性和 PerformStep 方法递增文件时的值 ProgressBar 。 此示例要求你有一个在一个中创建的名为 /> 的控件,并且创建了一个名为 的方法(返回指示文件复制操作已成功完成的文件复制操作)的方法。 该代码还要求创建包含要复制的文件的字符串数组,并将其传递给 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 ] ))
         {
            // 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]))
        {
            // 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

注解

此属性指定属性的 Value 上限。 更改属性的值 Maximum 时,将 ProgressBar 重新绘制控件以反映控件的新范围。 当属性的值 Value 等于属性的值 Maximum 时,进度栏将完全填充。

可以使用此属性指定属性必须设置的值 Value (通过设置 Value 属性或使用 Increment 或 PerformStep 方法)来指示操作已完成。 例如,可以将属性的值 Maximum 设置为文件复制操作中的文件总数。 每次复制文件时,属性都可以增加 1, Value 直到复制文件总数为止。 此时,进度栏将完全填充。

适用于

另请参阅