ProgressBar.PerformStep Metodo

Definizione

Sposta in avanti la posizione corrente dell'indicatore di stato in base al valore della proprietà Step.

public:
 void PerformStep();
public void PerformStep ();
member this.PerformStep : unit -> unit
Public Sub PerformStep ()

Eccezioni

Esempio

Nell'esempio di codice seguente viene usato un controllo per visualizzare lo stato di avanzamento di un'operazione ProgressBar di copia file. Nell'esempio ProgressBar vengono usate le Minimum proprietà e Maximum per specificare un intervallo 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. In questo esempio è necessario che sia stato creato un controllo denominato pBar1 creato all'interno di un Formoggetto e che sia stato creato un metodo denominato CopyFile (che restituisce un ProgressBar 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 una matrice di stringhe contenenti i file da copiare venga creata e passata al CopyWithProgress metodo definito nell'esempio e che il metodo venga chiamato da un altro metodo o evento nell'oggetto 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 ] ) == true )
         {
            // 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]) == true)
        {
            // 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

Il PerformStep metodo incrementa il valore della barra di stato in base alla quantità specificata dalla Step proprietà . È possibile utilizzare la Step proprietà per specificare l'importo che ogni attività completata in un'operazione modifica il valore della barra di stato. Ad esempio, se si copia un gruppo di file, è possibile impostare il valore della proprietà su 1 e il valore della Step 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 vuole avere un controllo più flessibile del valore della barra di stato, è possibile usare il metodo o impostare direttamente il Increment valore della Value proprietà.

La Value proprietà specifica la posizione corrente dell'oggetto ProgressBar. Se, dopo aver chiamato il PerformStep metodo, la Value proprietà è maggiore del valore della Maximum proprietà, la Value proprietà rimane al valore della Maximum proprietà. Se, dopo aver chiamato il PerformStep metodo con un valore negativo specificato in Step, la Value proprietà è minore del valore della proprietà, la Value proprietà rimane al valore della Minimum Minimum proprietà.

Poiché un ProgressBar oggetto il cui stile è impostato per Marquee visualizzare una barra di scorrimento continuo anziché la relativa Valuechiamata PerformStep non è necessaria e genererà un InvalidOperationExceptionoggetto .

Si applica a

Vedi anche