ProgressBar.Increment(Int32) Método
Definição
Importante
Algumas informações dizem respeito a um produto pré-lançado que pode ser substancialmente modificado antes de ser lançado. A Microsoft não faz garantias, de forma expressa ou implícita, em relação à informação aqui apresentada.
Avança a posição atual da barra de progresso pelo valor especificado.
public:
void Increment(int value);
public void Increment(int value);
member this.Increment : int -> unit
Public Sub Increment (value As Integer)
Parâmetros
- value
- Int32
O valor para incrementar a posição atual da barra de progresso.
Exceções
Exemplos
O exemplo de código seguinte demonstra como usar o Increment método e a Value propriedade para incrementar o valor de a ProgressBar no Tick caso de um Timer. O exemplo também apresenta a Value propriedade em a StatusBarPanel para fornecer uma representação textual do ProgressBar. Este exemplo exige que tenhas um ProgressBar controlo, chamado progressBar1, e um StatusBar controlo que contenha um StatusBarPanel, chamado statusBarPanel1. O Timer, denominado time, deve ser adicionado ao formulário como 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
Observações
O Increment método permite-lhe incrementar o valor da barra de progresso numa quantidade específica. Este método de incrementar a barra de progresso é semelhante ao uso da Step propriedade com o PerformStep método. A Value propriedade especifica a posição atual do ProgressBar. Se, após chamar o Increment método, a Value propriedade for maior do que o valor da Maximum propriedade, a Value propriedade mantém-se no valor da Maximum propriedade. Se, após chamar o Increment método com um valor negativo especificado no value parâmetro, a Value propriedade for inferior ao valor da Minimum propriedade, a Value propriedade mantém-se no valor da Minimum propriedade.
Como um ProgressBar objeto cujo estilo está definido para Marquee mostrar uma barra de scroll contínuo em vez do seu Value, chamar Increment é desnecessário e irá gerar um InvalidOperationException.