ProgressBar.Maximum 屬性

定義

取得或設定控制項範圍的最大值。Gets or sets the maximum value of the range of the control.

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

屬性值

Int32

範圍的最大值。The maximum value of the range. 預設值為 100。The default is 100.

例外狀況

指定的值小於 0。The value specified is less than 0.

範例

下列程式碼範例會使用 ProgressBar 控制項來顯示檔案複製作業的進度。The following code example uses a ProgressBar control to display the progress of a file copy operation. 此範例會使用 MinimumMaximum 屬性來指定的範圍,其 ProgressBar 相當於要複製的檔案數目。The example uses the Minimum and Maximum properties to specify a range for the ProgressBar that is equivalent to the number of files to copy. 程式碼也會搭配 Step 方法使用屬性, PerformStep 以便在複製檔案時遞增的值 ProgressBarThe code also uses the Step property with the PerformStep method to increment the value of the ProgressBar as a file is copied. 此範例會要求您建立一個 ProgressBar 呼叫的控制項,該控制項 pBar1 是在中建立的, Form 而且有一個稱為 CopyFile (的方法,它會傳回布林值,指出檔案複製作業已順利完成) 執行檔案複製作業。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 範例中所定義的方法,並且從中的另一個方法或事件呼叫該方法 FormThe code also requires that an array of strings containing the files to copy is created and passed to the CopyWithProgress method defined in the example and that the method is called from another method or event in the 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

備註

這個屬性會指定屬性的上限 ValueThis property specifies the upper limit of the Value property. 當屬性的值 Maximum 變更時, ProgressBar 會重新繪製控制項以反映控制項的新範圍。When the value of the Maximum property is changed, the ProgressBar control is redrawn to reflect the new range of the control. 當屬性的值 Value 等於屬性的值時 Maximum ,進度列就會完整填滿。When the value of the Value property is equal to the value of the Maximum property, the progress bar is completely filled.

您可以使用這個屬性來指定要設定屬性的值, Value (設定 Value 屬性,或使用 IncrementPerformStep 方法) 來指出作業已完成。You can use this property to specify a value to which the Value property must be set (by setting the Value property or using the Increment or PerformStep methods) to indicate that an operation is complete. 例如,您可以將屬性的值設定 Maximum 為檔案複製作業中的總檔案數。For example, you can set the value of the Maximum property to the total number of files in a file copy operation. 每次複製檔案時,屬性都 Value 可以增加1,直到複製檔案總數為止。Each time a file is copied, the Value property can be increased by 1 until the total number of files is copied. 屆時,進度列就會完全填滿。At that point, the progress bar would be completely filled.

適用於

另請參閱