Partager via


ProgressBar.Step Propriété

Définition

Obtient ou définit la quantité par laquelle un appel à la PerformStep() méthode augmente la position actuelle de la barre de progression.

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

Valeur de propriété

Quantité par laquelle incrémenter la barre de progression avec chaque appel à la PerformStep() méthode. La valeur par défaut est 10.

Exemples

L’exemple de code suivant utilise un ProgressBar contrôle pour afficher la progression d’une opération de copie de fichier. L’exemple utilise les propriétés et Maximum les Minimum propriétés pour spécifier une plage correspondant ProgressBar au nombre de fichiers à copier. Le code utilise également la Step propriété avec la PerformStep méthode pour incrémenter la valeur du ProgressBar fichier en tant que fichier copié. Cet exemple nécessite que vous ayez un ProgressBar contrôle créé appelé pBar1 qui est créé dans un Form, et qu’il existe une méthode créée appelée CopyFile (qui retourne une valeur booléenne indiquant que l’opération de copie de fichier a été effectuée avec succès) qui effectue l’opération de copie de fichier. Le code nécessite également qu’un tableau de chaînes contenant les fichiers à copier soit créé et transmis à la CopyWithProgress méthode définie dans l’exemple, et que la méthode est appelée à partir d’une autre méthode ou d’un autre événement dans l’exemple 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

Remarques

Vous pouvez utiliser la Step propriété pour spécifier le montant que chaque tâche terminée dans une opération modifie la valeur de la barre de progression. Par exemple, si vous copiez un groupe de fichiers, vous pouvez définir la valeur de la Step propriété sur 1 et la valeur de la Maximum propriété sur le nombre total de fichiers à copier. Lorsque chaque fichier est copié, vous pouvez appeler la PerformStep méthode pour incrémenter la barre de progression par la valeur de la Step propriété. Si vous souhaitez avoir un contrôle plus flexible de la valeur de la barre de progression, vous pouvez utiliser la Increment méthode ou définir la valeur de la Value propriété directement.

S’applique à

Voir aussi