Bagikan melalui


ProgressBar.Step Properti

Definisi

Mendapatkan atau mengatur jumlah panggilan ke PerformStep() metode meningkatkan posisi bilah kemajuan saat ini.

public:
 property int Step { int get(); void set(int value); };
public int Step { get; set; }
member this.Step : int with get, set
Public Property Step As Integer

Nilai Properti

Jumlah untuk menaikkan bilah kemajuan dengan setiap panggilan ke PerformStep() metode . Nilai default adalah 10.

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

Anda dapat menggunakan Step properti untuk menentukan jumlah setiap tugas yang diselesaikan dalam operasi mengubah nilai bilah kemajuan. Misalnya, jika Anda menyalin sekelompok file, Anda mungkin ingin mengatur nilai Step properti ke 1 dan nilai Maximum properti ke jumlah total file yang akan disalin. Ketika setiap file disalin, Anda dapat memanggil PerformStep metode untuk menaikkan bilah kemajuan dengan nilai Step properti . Jika Anda ingin memiliki kontrol nilai bilah kemajuan yang lebih fleksibel, Anda dapat menggunakan Increment metode atau mengatur nilai properti secara Value langsung.

Berlaku untuk

Lihat juga