Freigeben über


ProgressBar.Maximum Eigenschaft

Definition

Dient zum Abrufen oder Festlegen des Maximalwerts des Bereichs des Steuerelements.

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

Eigenschaftswert

Der Maximalwert des Bereichs. Der Standardwert ist 100.

Ausnahmen

Der angegebene Wert ist kleiner als 0.

Beispiele

Im folgenden Codebeispiel wird ein ProgressBar Steuerelement verwendet, um den Fortschritt eines Dateikopievorgangs anzuzeigen. Im Beispiel werden der Bereich und Maximum die Minimum Eigenschaften verwendet, um einen Bereich anzugeben, der ProgressBar der Anzahl der zu kopierenden Dateien entspricht. Der Code verwendet auch die Step Eigenschaft mit der PerformStep Methode, um den Wert der ProgressBar datei zu erhöhen. Dieses Beispiel erfordert, dass Sie ein ProgressBar Steuerelement erstellt haben, das innerhalb pBar1 einer Form erstellt wird, und dass eine Methode erstellt wird CopyFile (die einen booleschen Wert zurückgibt, der angibt, dass der Dateikopievorgang erfolgreich abgeschlossen wurde), die den Dateikopievorgang ausführt. Der Code erfordert außerdem, dass ein Array von Zeichenfolgen, die die zu kopierenden Dateien enthalten, erstellt und an die CopyWithProgress im Beispiel definierte Methode übergeben wird und dass die Methode von einer anderen Methode oder einem anderen Ereignis in der 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

Hinweise

Diese Eigenschaft gibt die obere Grenze der Value Eigenschaft an. Wenn der Wert der Maximum Eigenschaft geändert wird, wird das ProgressBar Steuerelement neu gezeichnet, um den neuen Bereich des Steuerelements widerzuspiegeln. Wenn der Wert der Value Eigenschaft gleich dem Wert der Maximum Eigenschaft ist, wird die Statusanzeige vollständig ausgefüllt.

Mit dieser Eigenschaft können Sie einen Wert angeben, auf den die Value Eigenschaft festgelegt werden muss (indem Sie die Value Eigenschaft festlegen oder die Increment Methoden PerformStep verwenden), um anzugeben, dass ein Vorgang abgeschlossen ist. Sie können z. B. den Wert der Maximum Eigenschaft auf die Gesamtanzahl der Dateien in einem Dateikopievorgang festlegen. Jedes Mal, wenn eine Datei kopiert wird, kann die Value Eigenschaft um 1 erhöht werden, bis die Gesamtanzahl der Dateien kopiert wird. Zu diesem Zeitpunkt wäre die Statusanzeige vollständig ausgefüllt.

Gilt für:

Weitere Informationen