ProgressBar.Increment(Int32) Metodo
Definizione
Importante
Alcune informazioni sono relative alla release non definitiva del prodotto, che potrebbe subire modifiche significative prima della release definitiva. Microsoft non riconosce alcuna garanzia, espressa o implicita, in merito alle informazioni qui fornite.
Sposta in avanti la posizione corrente dell'indicatore di stato in base all'importo specificato.
public:
void Increment(int value);
public void Increment(int value);
member this.Increment : int -> unit
Public Sub Increment (value As Integer)
Parametri
- value
- Int32
Quantità in base alla quale incrementare la posizione corrente dell'indicatore di stato.
Eccezioni
Esempio
Nell'esempio di codice seguente viene illustrato come utilizzare il Increment metodo e la Value proprietà per incrementare il valore di in ProgressBar caso Tick di .Timer Nell'esempio viene inoltre visualizzata la Value proprietà in per StatusBarPanel fornire una rappresentazione testuale dell'oggetto ProgressBar. In questo esempio è necessario disporre di un ProgressBar controllo denominato progressBar1e di un StatusBar controllo che contiene un StatusBarPaneloggetto , denominato statusBarPanel1. L'oggetto Timer, denominato time, deve essere aggiunto al form come membro.
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
Commenti
Il Increment metodo consente di incrementare il valore dell'indicatore di stato in base a un importo specifico. Questo metodo di incremento della barra di stato è simile all'uso della Step proprietà con il PerformStep metodo . La Value proprietà specifica la posizione corrente dell'oggetto ProgressBar. Se, dopo aver chiamato il Increment metodo , la Value proprietà è maggiore del valore della Maximum proprietà , la Value proprietà rimane al valore della Maximum proprietà . Se, dopo aver chiamato il Increment metodo con un valore negativo specificato nel value parametro , la Value proprietà è minore del valore della Minimum proprietà , la Value proprietà rimane al valore della Minimum proprietà .
Poiché un ProgressBar oggetto il cui stile è impostato su Marquee visualizza una barra di scorrimento continua anziché la relativa Value, la chiamata Increment non è necessaria e genera un oggetto InvalidOperationException.