Bagikan melalui


ProgressBar.Increment(Int32) Metode

Definisi

Memajukan posisi bilah kemajuan saat ini dengan jumlah yang ditentukan.

public:
 void Increment(int value);
public void Increment (int value);
member this.Increment : int -> unit
Public Sub Increment (value As Integer)

Parameter

value
Int32

Jumlah untuk menaikkan posisi bilah kemajuan saat ini.

Pengecualian

Contoh

Contoh kode berikut menunjukkan cara menggunakan Increment metode dan Value properti untuk menaikkan nilai jika ProgressBarTick terjadi Timer. Contoh ini juga menampilkan Value properti dalam StatusBarPanel untuk memberikan representasi tekstual dari ProgressBar. Contoh ini mengharuskan Anda memiliki ProgressBar kontrol, bernama progressBar1, dan StatusBar kontrol yang berisi StatusBarPanel, bernama statusBarPanel1. Timer, bernama time, harus ditambahkan ke formulir sebagai anggota.

private:
   Timer^ time;

   // Call this method from the constructor of the form.
   void InitializeMyTimer()
   {
      // Set the interval for the timer.
      time->Interval = 250;

      // Connect the Tick event of the timer to its event handler.
      time->Tick += gcnew EventHandler( this, &Form1::IncreaseProgressBar );

      // Start the timer.
      time->Start();
   }

   void IncreaseProgressBar( Object^ /*sender*/, EventArgs^ /*e*/ )
   {
      // Increment the value of the ProgressBar a value of one each time.
      progressBar1->Increment( 1 );

      // Display the textual value of the ProgressBar in the StatusBar control's first panel.
      statusBarPanel1->Text = String::Concat( progressBar1->Value, "% Completed" );

      // Determine if we have completed by comparing the value of the Value property to the Maximum value.
      if ( progressBar1->Value == progressBar1->Maximum )

      // Stop the timer.
      time->Stop();
   }
private Timer time = new Timer();

// Call this method from the constructor of the form.
private void InitializeMyTimer()
{
   // Set the interval for the timer.
   time.Interval = 250;
   // Connect the Tick event of the timer to its event handler.
   time.Tick += new EventHandler(IncreaseProgressBar);
   // Start the timer.
   time.Start();
}

private void IncreaseProgressBar(object sender, EventArgs e)
{
   // Increment the value of the ProgressBar a value of one each time.
   progressBar1.Increment(1);
   // Display the textual value of the ProgressBar in the StatusBar control's first panel.
   statusBarPanel1.Text = progressBar1.Value.ToString() + "% Completed";
   // Determine if we have completed by comparing the value of the Value property to the Maximum value.
   if (progressBar1.Value == progressBar1.Maximum)
      // Stop the timer.
      time.Stop();
}
Private time As New Timer()

' Call this method from the constructor of the form.
Private Sub InitializeMyTimer()
   ' Set the interval for the timer.
   time.Interval = 250
   ' Connect the Tick event of the timer to its event handler.
   AddHandler time.Tick, AddressOf IncreaseProgressBar
   ' Start the timer.
   time.Start()
End Sub


Private Sub IncreaseProgressBar(ByVal sender As Object, ByVal e As EventArgs)
   ' Increment the value of the ProgressBar a value of one each time.
   ProgressBar1.Increment(1)
   ' Display the textual value of the ProgressBar in the StatusBar control's first panel.
   statusBarPanel1.Text = ProgressBar1.Value.ToString() + "% Completed"
   ' Determine if we have completed by comparing the value of the Value property to the Maximum value.
   If ProgressBar1.Value = ProgressBar1.Maximum Then
      ' Stop the timer.
      time.Stop()
   End If
End Sub

Keterangan

Metode ini Increment memungkinkan Anda untuk menaikkan nilai bilah kemajuan dengan jumlah tertentu. Metode untuk meningkatkan bilah kemajuan ini mirip dengan menggunakan Step properti dengan PerformStep metode . Properti Value menentukan posisi saat ini dari ProgressBar. Jika, setelah memanggil Increment metode , Value properti lebih besar dari Maximum nilai properti , Value properti tetap pada nilai Maximum properti . Jika, setelah memanggil Increment metode dengan nilai negatif yang ditentukan dalam value parameter , 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 menggulir alih-alih Value, panggilan Increment tidak perlu dan akan menaikkan InvalidOperationException.

Berlaku untuk

Lihat juga