ProgressBar.Step Proprietà
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.
Ottiene o imposta la quantità in base alla quale una chiamata al PerformStep() metodo aumenta la posizione corrente dell'indicatore di stato.
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
Valore della proprietà
Quantità in base alla quale incrementare l'indicatore di stato con ogni chiamata al PerformStep() metodo . Il valore predefinito è 10.
Esempio
Nell'esempio di codice seguente viene utilizzato un ProgressBar controllo per visualizzare lo stato di avanzamento di un'operazione di copia file. Nell'esempio vengono utilizzate le Minimum proprietà e Maximum per specificare un intervallo per l'oggetto ProgressBar equivalente al numero di file da copiare. Il codice usa anche la Step proprietà con il PerformStep metodo per incrementare il valore di ProgressBar come file viene copiato. Questo esempio richiede che sia stato creato un ProgressBar controllo denominato pBar1 creato all'interno di un Formoggetto e che sia stato creato un metodo denominato CopyFile (che restituisce un valore booleano che indica che l'operazione di copia file è stata completata correttamente) che esegue l'operazione di copia file. Il codice richiede inoltre che venga creata e passata una matrice di stringhe contenenti i file da copiare al CopyWithProgress metodo definito nell'esempio e che il metodo venga chiamato da un altro metodo o evento in 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
Commenti
È possibile utilizzare la Step proprietà per specificare la quantità di modifiche apportate a ogni attività completata in un'operazione. Ad esempio, se si copia un gruppo di file, è possibile impostare il valore della Step proprietà su 1 e il valore della Maximum proprietà sul numero totale di file da copiare. Quando ogni file viene copiato, è possibile chiamare il PerformStep metodo per incrementare la barra di stato in base al valore della Step proprietà . Se si desidera avere un controllo più flessibile del valore dell'indicatore di stato, è possibile utilizzare il Increment metodo o impostare direttamente il valore della Value proprietà.