ProgressBar.Step ProgressBar.Step ProgressBar.Step ProgressBar.Step Property

定义

获取或设置调用 PerformStep() 方法增加进度栏的当前位置时所根据的数量。Gets or sets the amount by which a call to the PerformStep() method increases the current position of the progress bar.

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

属性值

每次调用 PerformStep() 方法增加进度栏时所根据的数量。The amount by which to increment the progress bar with each call to the PerformStep() method. 默认值为 10。The default is 10.

示例

下面的代码示例使用ProgressBar控件显示文件复制操作的进度。The following code example uses a ProgressBar control to display the progress of a file copy operation. 该示例使用MinimumMaximum属性来ProgressBar指定的范围, 该范围等效于要复制的文件数。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. 此代码还将Step属性PerformStep与方法一起使用, 以在复制文件时ProgressBar递增的值。The code also uses the Step property with the PerformStep method to increment the value of the ProgressBar as a file is copied. 此示例需要ProgressBar在中创建一个名pBar1Form的控件, 并在其中创建了一个调用CopyFile的方法 (该方法返回一个布尔值, 指示文件复制操作是已成功完成) 执行文件复制操作。This example requires 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. 此代码还要求创建包含要复制的文件的字符串数组, 并将其传递给在CopyWithProgress此示例中定义的方法, 并在Form中从另一个方法或事件调用此方法。The code also requires 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.

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

注解

您可以使用Step属性来指定操作中每个已完成任务更改进度栏值的量。You can use the Step property to specify the amount that each completed task in an operation changes the value of the progress bar. 例如, 如果要复制一组文件, 则可能需要将Step属性的值设置为 1, 并将Maximum属性的值设置为要复制的文件的总数。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. 在复制每个文件时, 可以调用PerformStep方法, 以通过Step属性的值递增进度栏。When each file is copied, you can call the PerformStep method to increment the progress bar by the value of the Step property. 如果希望更灵活地控制进度栏的值, 可以使用Increment方法或直接设置Value属性的值。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.

适用于

另请参阅