ProgressBar.Maximum 属性  
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
获取或设置控件范围的最大值。
public:
 property int Maximum { int get(); void set(int value); };public int Maximum { get; set; }member this.Maximum : int with get, setPublic Property Maximum As Integer属性值
范围的最大值。 默认值为 100。
例外
指定的值小于 0。
示例
下面的代码示例使用 ProgressBar 控件显示文件复制操作的进度。 该示例使用 Minimum 和 Maximum 属性为等效于要复制的文件数指定范围 ProgressBar 。 该代码还使用 Step 具有方法的属性 PerformStep 来递增复制文件时的值 ProgressBar 。 This example requires that you have a ProgressBar control created called pBar1 that is created within a Form and that there is a method created called CopyFile (that returns a Boolean value indicating the file copy operation was completed successfully) that performs the file copy operation. 该代码还要求创建包含要复制的文件的字符串数组,并将其传递到 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
注解
此属性指定属性的 Value 上限。 更改属性的值 Maximum 时,将 ProgressBar 重新绘制控件以反映控件的新范围。 当属性的值等于属性的值ValueMaximum时,进度栏将完全填充。
可以使用此属性指定属性必须设置 (的值 Value ,方法是设置 Value 属性或使用 Increment) PerformStep 方法指示操作已完成。 例如,可以将属性的值 Maximum 设置为文件复制操作中的文件总数。 每次复制文件时, Value 属性都可以增加 1,直到复制文件总数为止。 此时,进度栏将完全填充。