Export (0) Print
Expand All

ProgressBar.Step Property

Gets or sets the amount by which a call to the PerformStep method increases the current position of the progress bar.

[Visual Basic]
Public Property Step As Integer
[C#]
public int Step {get; set;}
[C++]
public: __property int get_Step();
public: __property void set_Step(int);
[JScript]
public function get Step() : int;
public function set Step(int);

Property Value

The amount by which to increment the progress bar with each call to the PerformStep method. The default is 10.

Remarks

You can use the Step property to specify the amount that each completed task in an operation changes the value of the progress bar. For example, if you are copying a group of files, you might want to set the value of the Step property to 1 and the value of the Maximum property to the total number of files to copy. When each file is copied, you can call the PerformStep method to increment the progress bar by the value of the Step property. If you want to have more flexible control of the value of the progress bar, you can use the Increment method or set the value of the Value property directly.

Example

[Visual Basic, C#, C++] The following example uses a ProgressBar control to display the progress of a file copy operation. The example uses the Minimum and Maximum properties to specify a range for the ProgressBar that is equivalent to the number of files to copy. The code also uses the Step property with the PerformStep method to increment the value of the ProgressBar as a file is copied. This example assumes that you have a ProgressBar control created called pBar1 that is created within a Form and that there is a method created called CopyFile (that returns a Boolean value indicating the file copy operation was completed successfully) that performs the file copy operation. The code also assumes that an array of strings containing the files to copy is created and passed to the CopyWithProgress method defined in the example and that the method is called from another method or event in the Form.

[Visual Basic] 
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

[C#] 
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();
        }
    }
}

[C++] 
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();
         }
      }
   }

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

See Also

ProgressBar Class | ProgressBar Members | System.Windows.Forms Namespace | PerformStep | Value | Increment

Show:
© 2014 Microsoft