ProgressBar.Value Tulajdonság
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.
Lekéri vagy beállítja a folyamatjelző sáv aktuális pozícióját.
public:
property int Value { int get(); void set(int value); };
[System.ComponentModel.Bindable(true)]
public int Value { get; set; }
[<System.ComponentModel.Bindable(true)>]
member this.Value : int with get, set
Public Property Value As Integer
Tulajdonság értéke
A helyzet a folyamatjelző sáv tartományán belül. Az alapértelmezett érték a 0.
- Attribútumok
Kivételek
A megadott érték nagyobb, mint a Maximum tulajdonság értéke.
-vagy-
A megadott érték kisebb, mint a Minimum tulajdonság értéke.
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 StatusBarPanelvezérlőelemet kell létrehozniastatusBarPanel1. 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 tulajdonság minimális és maximális értékeit a ValueMinimumMaximum tulajdonságok adhatók meg. Ez a tulajdonság lehetővé teszi a folyamatjelző sáv értékének közvetlen növelését vagy csökkenését. A vezérlőelem értékének ProgressBar konzisztens növeléséhez használhatja a Step tulajdonságot a PerformStep metódussal. A folyamatjelző sáv értékének különböző mennyiségekkel való növeléséhez használja a metódust Increment .