ProgressBar.Step Egenskap
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.
Hämtar eller anger hur mycket ett anrop till PerformStep() metoden ökar den aktuella positionen för förloppsindikatorn.
public:
property int Step { int get(); void set(int value); };
public int Step { get; set; }
member this.Step : int with get, set
Public Property Step As Integer
Egenskapsvärde
Hur mycket för att öka förloppsindikatorn med varje anrop till PerformStep() metoden. Standardvärdet är 10.
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
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.