Bagikan melalui


ProgressBar.Maximum Properti

Definisi

Mendapatkan atau mengatur nilai maksimum rentang kontrol.

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

Nilai Properti

Nilai maksimum rentang. Nilai defaultnya adalah 100.

Pengecualian

Nilai yang ditentukan kurang dari 0.

Contoh

Contoh kode berikut menggunakan ProgressBar kontrol untuk menampilkan kemajuan operasi penyalinan file. Contoh menggunakan Minimum properti dan Maximum untuk menentukan rentang yang ProgressBar setara dengan jumlah file yang akan disalin. Kode ini juga menggunakan Step properti dengan PerformStep metode untuk menaikkan nilai ProgressBar saat file disalin. Contoh ini mengharuskan Anda memiliki ProgressBar kontrol yang dibuat yang disebut pBar1 yang dibuat dalam Form dan bahwa ada metode yang dibuat yang disebut CopyFile (yang mengembalikan nilai Boolean yang menunjukkan operasi penyalinan file berhasil diselesaikan) yang melakukan operasi penyalinan file. Kode ini juga mengharuskan array string yang berisi file untuk disalin dibuat dan diteruskan ke CopyWithProgress metode yang ditentukan dalam contoh dan bahwa metode dipanggil dari metode atau peristiwa lain di 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

Keterangan

Properti ini menentukan batas Value atas properti. Ketika nilai Maximum properti diubah, ProgressBar kontrol digambar ulang untuk mencerminkan rentang kontrol baru. Ketika nilai Value properti sama dengan nilai Maximum properti, bilah kemajuan benar-benar terisi.

Anda dapat menggunakan properti ini untuk menentukan nilai yang Value harus diatur properti (dengan mengatur Value properti atau menggunakan Increment metode atau PerformStep ) untuk menunjukkan bahwa operasi selesai. Misalnya, Anda dapat mengatur nilai Maximum properti ke jumlah total file dalam operasi penyalinan file. Setiap kali file disalin, Value properti dapat ditingkatkan 1 hingga jumlah total file disalin. Pada saat itu, bilah kemajuan akan benar-benar terisi.

Berlaku untuk

Lihat juga