共用方式為


ProgressBar.Step 屬性

定義

取得或設定呼叫該方法時,進度條當前位置增加 PerformStep() 的幅度。

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() 方法時,進度條的增加量。 預設值為 10。

範例

以下程式碼範例使用 ProgressBar 控制項來顯示檔案複製操作的進度。 範例中使用 和 MinimumMaximum 屬性來指定一個等價於複製檔案數量的範圍 ProgressBar 。 程式碼也使用 StepPerformStep 屬性,並以該方法在檔案複製時增加 的 ProgressBar 值。 這個範例需要你建立一個 ProgressBar 在 中建立的 pBar1 控制項,該控制項是在 中建立 Form的,並且有一個稱為 CopyFile 的方法(回傳一個布林值,表示檔案複製操作已成功完成)來執行檔案複製操作。 程式碼還要求建立包含要複製檔案的字串陣列並傳給 CopyWithProgress 範例中定義的方法,且該方法必須從 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

備註

你可以用這個 Step 屬性來指定每個完成任務會改變進度條值的金額。 舉例來說,如果你要複製一組檔案,你可能會想將屬性的值 Step 設為 1,屬性的值 Maximum 設為要複製的檔案總數。 當每個檔案被複製後,你可以呼叫 PerformStep 這個方法,讓進度條依照屬性 Step 的值遞增。 如果你想更靈活地控制進度條的值,可以用這個 Increment 方法或直接設定屬性的值 Value

適用於

另請參閱