ProgressBar.PerformStep Metódus

Definíció

A folyamatjelző sáv aktuális pozícióját a tulajdonság összegével Step ja meg.

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

Kivételek

Style Marqueeértékre van állítva.

Példák

Az alábbi példakód egy vezérlővel ProgressBar jeleníti meg a fájlmásolási művelet előrehaladását. A példa a Minimum tulajdonságokat használva Maximum a másolandó fájlok számával egyenértékű tartományt ProgressBar ad meg. A kód a Step tulajdonságot is használja a PerformStep metódussal a fájl másolásának értékének ProgressBar növeléséhez. Ehhez a példához létre kell hoznia egy ProgressBar vezérlőelemet, amely egy, a Formfájlmásolási műveletet végrehajtó metódust hoz létre pBar1CopyFile (amely egy logikai értéket ad vissza, amely azt jelzi, hogy a fájlmásolási művelet sikeresen befejeződött). A kódhoz emellett létre kell hoznia és továbbítania CopyWithProgress kell a példában meghatározott metódusnak a másolandó fájlokat tartalmazó sztringekből álló tömböt, és a metódust egy másik metódusból vagy eseményből kell meghívni a Formpéldában.

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

Megjegyzések

A PerformStep metódus a tulajdonság által Step megadott összeggel növeli a folyamatjelző sáv értékét. A tulajdonság használatával Step megadhatja, hogy egy művelet egyes befejezett tevékenységei milyen mértékben módosítják a folyamatjelző sáv értékét. Ha például egy fájlcsoportot másol, érdemes lehet a tulajdonság értékét Step 1 értékre állítani, a Maximum tulajdonság értékét pedig a másolandó fájlok teljes számára. Az egyes fájlok másolásakor meghívhatja a metódust, PerformStep hogy a tulajdonság értékével növelje a folyamatjelző sávot Step . Ha rugalmasabban szeretné szabályozni a folyamatjelző sáv értékét, használhatja a Increment metódust, vagy beállíthatja közvetlenül a Value tulajdonság értékét.

A Value tulajdonság a ProgressBar. Ha a metódus meghívása PerformStep után a Value tulajdonság nagyobb, mint a Maximum tulajdonság értéke, a Value tulajdonság a tulajdonság értéke Maximum marad. Ha a metódusnak a PerformStep megadott Stepnegatív értékkel való meghívása után a Value tulajdonság kisebb, mint a Minimum tulajdonság értéke, a Value tulajdonság a tulajdonság értékénél Minimum marad.

Mivel egy ProgressBar objektum, amelynek stílusa úgy van beállítva, hogy ahelyett, hogy Marquee folyamatosan görgető sávot jelenítenének Valuemeg, a hívás PerformStep szükségtelen, és fel fog emelni egy InvalidOperationException.

A következőre érvényes:

Lásd még