ProgressBar.Maximum Egenskap

Definition

Hämtar eller anger det maximala värdet för kontrollens intervall.

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

Egenskapsvärde

Det maximala värdet för intervallet. Standardinställningen är 100.

Undantag

Det angivna värdet är mindre än 0.

Exempel

I följande kodexempel används en ProgressBar kontroll för att visa förloppet för en filkopieringsåtgärd. I exemplet används Minimum egenskaperna och Maximum för att ange ett intervall för ProgressBar det som motsvarar antalet filer som ska kopieras. Koden använder Step också egenskapen med PerformStep metoden för att öka värdet för som ProgressBar en fil kopieras. Det här exemplet kräver att du har en ProgressBar kontroll som skapats med namnet pBar1 som skapas i en Form och att det finns en metod som skapats med namnet CopyFile (som returnerar ett booleskt värde som anger att filkopieringsåtgärden har slutförts) som utför filkopieringsåtgärden. Koden kräver också att en matris med strängar som innehåller filerna som ska kopieras skapas och skickas till metoden CopyWithProgress som definieras i exemplet och att metoden anropas från en annan metod eller händelse i 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

Kommentarer

Den här egenskapen anger den övre gränsen för Value egenskapen. När värdet för Maximum egenskapen ändras ProgressBar ritas kontrollen om för att återspegla kontrollens nya intervall. När värdet för Value egenskapen är lika med värdet för Maximum egenskapen fylls förloppsindikatorn helt.

Du kan använda den här egenskapen för att ange ett värde som Value egenskapen måste anges till (genom att ange Value egenskapen eller använda Increment metoderna eller PerformStep ) för att indikera att en åtgärd är slutförd. Du kan till exempel ange värdet Maximum för egenskapen till det totala antalet filer i en filkopieringsåtgärd. Varje gång en fil kopieras Value kan egenskapen ökas med 1 tills det totala antalet filer kopieras. Då skulle förloppsindikatorn vara helt fylld.

Gäller för

Se även