Bagikan melalui


ProgressBar.PerformStep Metode

Definisi

Memajukan posisi bilah kemajuan saat ini dengan jumlah Step properti.

public:
 void PerformStep();
public void PerformStep();
member this.PerformStep : unit -> unit
Public Sub PerformStep ()

Pengecualian

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

Metode ini PerformStep menaikkan nilai bilah kemajuan dengan jumlah yang ditentukan oleh Step properti . 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.

Properti Value menentukan posisi saat ini dari ProgressBar. Jika, setelah memanggil PerformStep metode , Value properti lebih besar dari nilai Maximum properti , Value properti tetap pada nilai Maximum properti . Jika, setelah memanggil PerformStep metode dengan nilai negatif yang ditentukan dalam Step, Value properti kurang dari Minimum nilai properti , Value properti tetap pada nilai Minimum properti .

ProgressBar Karena objek yang gayanya diatur untuk Marquee menampilkan bilah yang terus bergulir alih-alih Value, panggilan PerformStep tidak perlu dan akan menaikkan InvalidOperationException.

Berlaku untuk

Lihat juga