ProgressBar.Increment(Int32) Metoda
Definice
Důležité
Některé informace platí pro předběžně vydaný produkt, který se může zásadně změnit, než ho výrobce nebo autor vydá. Microsoft neposkytuje žádné záruky, výslovné ani předpokládané, týkající se zde uváděných informací.
Posune aktuální pozici indikátoru průběhu o zadanou částku.
public:
void Increment(int value);
public void Increment(int value);
member this.Increment : int -> unit
Public Sub Increment (value As Integer)
Parametry
- value
- Int32
Hodnota, o kterou chcete zvýšit aktuální pozici indikátoru průběhu.
Výjimky
Příklady
Následující příklad kódu ukazuje, jak použít metodu IncrementValue a vlastnost zvýšit hodnotu v ProgressBarTick případě události Timer. Příklad také zobrazí Value vlastnost v objektu StatusBarPanel pro poskytnutí textové reprezentace objektu ProgressBar. Tento příklad vyžaduje, abyste měli ProgressBar ovládací prvek s názvem progressBar1a StatusBar ovládací prvek, který obsahuje pojmenovaný StatusBarPanelstatusBarPanel1. Název Timer, timemusí být přidán do formuláře jako člen.
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
Poznámky
Tato Increment metoda umožňuje zvýšit hodnotu indikátoru průběhu o určitou částku. Tato metoda zvýšení indikátoru průběhu je podobná použití Step vlastnosti s metodou PerformStep . Vlastnost Value určuje aktuální pozici objektu ProgressBar. Pokud je vlastnost po volání Increment metody Value větší než hodnota Maximum vlastnosti, Value zůstane vlastnost na hodnotě Maximum vlastnosti. Pokud po volání Increment metody s zápornou hodnotou zadanou v value parametru Value je vlastnost menší než hodnota Minimum vlastnosti, Value vlastnost zůstane na hodnotě Minimum vlastnosti.
Vzhledem k tomu, že ProgressBar objekt, jehož styl je nastaven tak, aby Marquee zobrazoval nepřetržitě posuvník místo jeho Value, volání Increment je zbytečné a vyvolá .InvalidOperationException