ProgressBar.PerformStep Metod
Definition
Viktigt
En del information gäller för förhandsversionen av en produkt och kan komma att ändras avsevärt innan produkten blir allmänt tillgänglig. Microsoft lämnar inga garantier, uttryckliga eller underförstådda, avseende informationen som visas här.
Flyttar fram den aktuella positionen för förloppsindikatorn med egenskapens Step belopp.
public:
void PerformStep();
public void PerformStep();
member this.PerformStep : unit -> unit
Public Sub PerformStep ()
Undantag
Exempel
I följande kodexempel används en ProgressBar kontroll för att visa förloppet för en filkopieringsåtgärd. I exemplet används Minimum egenskaperna och Maximum för att ange ett intervall för ProgressBar det som motsvarar antalet filer som ska kopieras. Koden använder Step också egenskapen med PerformStep metoden för att öka värdet för som ProgressBar en fil kopieras. Det här exemplet kräver att du har en ProgressBar kontroll som skapats med namnet pBar1 som skapas i en Form, och att det finns en metod som skapats med namnet CopyFile (som returnerar ett booleskt värde som anger att filkopieringsåtgärden har slutförts) som utför filkopieringsåtgärden. Koden kräver också att en matris med strängar som innehåller filerna som ska kopieras skapas och skickas till den CopyWithProgress metod som definieras i exemplet och att metoden anropas från en annan metod eller händelse i Form.
private:
void CopyWithProgress( array<String^>^filenames )
{
// Display the ProgressBar control.
pBar1->Visible = true;
// Set Minimum to 1 to represent the first file being copied.
pBar1->Minimum = 1;
// Set Maximum to the total number of files to copy.
pBar1->Maximum = filenames->Length;
// Set the initial value of the ProgressBar.
pBar1->Value = 1;
// Set the Step property to a value of 1 to represent each file being copied.
pBar1->Step = 1;
// Loop through all files to copy.
for ( int x = 1; x <= filenames->Length; x++ )
{
// Copy the file and increment the ProgressBar if successful.
if ( CopyFile( filenames[ x - 1 ] ))
{
// Perform the increment on the ProgressBar.
pBar1->PerformStep();
}
}
}
private void CopyWithProgress(string[] filenames)
{
// Display the ProgressBar control.
pBar1.Visible = true;
// Set Minimum to 1 to represent the first file being copied.
pBar1.Minimum = 1;
// Set Maximum to the total number of files to copy.
pBar1.Maximum = filenames.Length;
// Set the initial value of the ProgressBar.
pBar1.Value = 1;
// Set the Step property to a value of 1 to represent each file being copied.
pBar1.Step = 1;
// Loop through all files to copy.
for (int x = 1; x <= filenames.Length; x++)
{
// Copy the file and increment the ProgressBar if successful.
if (CopyFile(filenames[x-1]))
{
// Perform the increment on the ProgressBar.
pBar1.PerformStep();
}
}
}
Private Sub CopyWithProgress(ByVal ParamArray filenames As String())
' Display the ProgressBar control.
pBar1.Visible = True
' Set Minimum to 1 to represent the first file being copied.
pBar1.Minimum = 1
' Set Maximum to the total number of files to copy.
pBar1.Maximum = filenames.Length
' Set the initial value of the ProgressBar.
pBar1.Value = 1
' Set the Step property to a value of 1 to represent each file being copied.
pBar1.Step = 1
' Loop through all files to copy.
Dim x As Integer
for x = 1 To filenames.Length - 1
' Copy the file and increment the ProgressBar if successful.
If CopyFile(filenames(x - 1)) = True Then
' Perform the increment on the ProgressBar.
pBar1.PerformStep()
End If
Next x
End Sub
Kommentarer
Metoden PerformStep ökar värdet för förloppsindikatorn med det belopp som anges av Step egenskapen. Du kan använda Step egenskapen för att ange hur mycket varje slutförd aktivitet i en åtgärd ändrar värdet för förloppsindikatorn. Om du till exempel kopierar en grupp filer kanske du vill ange värdet Step för egenskapen till 1 och värdet Maximum för egenskapen till det totala antalet filer som ska kopieras. När varje fil kopieras kan du anropa PerformStep metoden för att öka förloppsindikatorn med värdet för Step egenskapen. Om du vill ha mer flexibel kontroll över förloppsindikatorns värde kan du använda Increment metoden eller ange värdet för Value egenskapen direkt.
Egenskapen Value anger den aktuella positionen för ProgressBar. Om egenskapen efter att ha anropat PerformStep metoden Value är större än värdet för Maximum egenskapen förblir Value egenskapen värdet för Maximum egenskapen. Om egenskapen efter att ha anropat PerformStep metoden med ett negativt värde som anges i StepValueär mindre än värdet för Minimum egenskapen, Value förblir egenskapen värdet för Minimum egenskapen.
Eftersom ett ProgressBar objekt vars formatmall är inställd på att Marquee visa en löpande rullningslist i stället för dess Value, är anropet PerformStep onödigt och genererar en InvalidOperationException.