Freigeben über


ProgressBar.Step-Eigenschaft

Ruft den Betrag ab, um den die PerformStep-Methode die aktuelle Position der Statusanzeige erhöht, oder legt diesen fest.

Namespace: System.Windows.Forms
Assembly: System.Windows.Forms (in system.windows.forms.dll)

Syntax

'Declaration
Public Property Step As Integer
'Usage
Dim instance As ProgressBar
Dim value As Integer

value = instance.Step

instance.Step = value
public int Step { get; set; }
public:
property int Step {
    int get ();
    void set (int value);
}
/** @property */
public int get_Step ()

/** @property */
public void set_Step (int value)
public function get Step () : int

public function set Step (value : int)

Eigenschaftenwert

Der Betrag, um den die Statusanzeige bei jedem Aufruf der PerformStep-Methode erhöht werden soll. Der Standardwert ist 10.

Hinweise

Sie können zum Angeben des Betrags, um den jede abgeschlossene Aufgabe eines Vorgangs den Wert der Statusanzeige ändert, die Step-Eigenschaft verwenden. Wenn Sie z. B. mehrere Dateien kopieren, können Sie den Wert der Step-Eigenschaft auf 1 und den Wert der Maximum-Eigenschaft auf die Gesamtzahl der zu kopierenden Dateien festlegen. Beim Kopieren jeder Datei können Sie die PerformStep-Methode aufrufen und so die Statusanzeige um den Wert der Step-Eigenschaft erhöhen. Wenn Sie den Wert der Statusanzeige flexibler steuern möchten, können Sie die Increment-Methode verwenden oder den Wert der Value-Eigenschaft direkt festlegen.

Beispiel

Im folgenden Codebeispiel wird anhand des ProgressBar-Steuerelements das Anzeigen des Fortschritts beim Kopieren von Dateien veranschaulicht. Im Beispiel werden die Minimum-Eigenschaft und die Maximum-Eigenschaft verwendet, um einen Bereich für die ProgressBar anzugeben, der der Anzahl der zu kopierenden Dateien entspricht. Im Code wird auch die Step-Eigenschaft mit der PerformStep-Methode verwendet, um den Wert von ProgressBar zu erhöhen, wenn eine Datei kopiert wurde. Für dieses Beispiel ist es erforderlich, dass Sie ein ProgressBar-Steuerelement mit dem Namen pBar1 in einem Form sowie eine Methode mit dem Namen CopyFile erstellt haben, die den Dateikopiervorgang durchführt. Diese Methode gibt einen booleschen Wert zurück, der die erfolgreiche Durchführung des Vorgangs angibt. Für diesen Code ist es außerdem erforderlich, dass ein Zeichenfolgenarray mit den zu kopierenden Dateien erstellt und an die im Beispiel definierte CopyWithProgress-Methode übergeben wird und die Methode von einer anderen Methode oder einem Ereignis im Form aufgerufen wird.

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
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:
   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.set_Visible(true);
    // Set Minimum to 1 to represent the first file being copied.
    pBar1.set_Minimum(1);
    // Set Maximum to the total number of files to copy.
    pBar1.set_Maximum(fileNames.get_Length());
    // Set the initial value of the ProgressBar.
    pBar1.set_Value(1);
    // Set the Step property to a value of 1 to represent each file
    // being copied.
    pBar1.set_Step(1);
    // Loop through all files to copy.
    for (int x = 1; x <= fileNames.get_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();
        }
    }
} //CopyWithProgress

Plattformen

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile für Pocket PC, Windows Mobile für Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

.NET Framework unterstützt nicht alle Versionen sämtlicher Plattformen. Eine Liste der unterstützten Versionen finden Sie unter Systemanforderungen.

Versionsinformationen

.NET Framework

Unterstützt in: 2.0, 1.1, 1.0

Siehe auch

Referenz

ProgressBar-Klasse
ProgressBar-Member
System.Windows.Forms-Namespace
PerformStep
Value
Increment