ProgressBar.Increment(Int32) Metódus
Definíció
Fontos
Egyes információk olyan, kiadás előtti termékekre vonatkoznak, amelyek a kiadásig még jelentősen módosulhatnak. A Microsoft nem vállal kifejezett vagy törvényi garanciát az itt megjelenő információért.
A megadott összeggel előrehalad a folyamatjelző sáv aktuális pozíciójának előrehaladtával.
public:
void Increment(int value);
public void Increment(int value);
member this.Increment : int -> unit
Public Sub Increment (value As Integer)
Paraméterek
- value
- Int32
Az az összeg, amellyel a folyamatjelző sáv aktuális pozícióját növelni szeretné.
Kivételek
Példák
Az alábbi példakód bemutatja, hogyan lehet a Increment metódust és a Value tulajdonságot használni egy ProgressBarTick érték növeléséhez egy Timer. A példa egy Value tulajdonságot StatusBarPanel is megjelenít, amely szövegesen ábrázolja a tulajdonságot ProgressBar. Ebben a példában egy ProgressBar elnevezett progressBar1vezérlőelemet és egy StatusBar , elnevezett statusBarPanel1vezérlőelemet kell létrehozniaStatusBarPanel. A Timernévvel ellátott timeűrlapot tagként kell hozzáadni az űrlaphoz.
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
Megjegyzések
A Increment metódus lehetővé teszi a folyamatjelző sáv értékének egy adott összeggel történő növelését. A folyamatjelző sáv növelésének ez a módszere hasonló a Step tulajdonság metódussal való PerformStep használatához. A Value tulajdonság a ProgressBar. Ha a metódus meghívása Increment után a Value tulajdonság nagyobb, mint a Maximum tulajdonság értéke, a Value tulajdonság a tulajdonság értéke Maximum marad. Ha a Increment metódus paraméterben value megadott negatív értékkel való meghívása után a Value tulajdonság kisebb, mint a Minimum tulajdonság értéke, a Value tulajdonság a tulajdonság értékénél Minimum marad.
Mivel egy ProgressBar objektum, amelynek stílusa úgy van beállítva, hogy ahelyett, hogy Marquee folyamatosan görgető sávot jelenítenének Valuemeg, a hívás Increment szükségtelen, és fel fog emelni egy InvalidOperationException.