ProgressBar.PerformStep メソッド

定義

プログレス バーの現在位置を Step プロパティの値の分だけ進めます。

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

例外

StyleMarquee に設定されます。

次のコード例では、コントロールを ProgressBar 使用してファイルコピー操作の進行状況を表示します。 この例では、and Maximum プロパティをMinimum使用して、コピーするファイルの数と同じ範囲ProgressBarを指定します。 また、このコードでは、 Step このプロパティをメソッドと共に PerformStep 使用して、コピーされるファイルの値 ProgressBar をインクリメントします。 この例では、呼び出されたpBar1コントロールを作成し、その中にForm作成されたメソッド (ファイル コピー操作が正常に完了したことを示すブール値を返す) が作成CopyFileされ、ファイル コピー操作を実行する必要ProgressBarがあります。 また、このコードでは、コピーするファイルを含む文字列の配列を作成し、この例で定義されているメソッドに 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 ] ) == 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

注釈

メソッドは PerformStep 、プロパティで指定された量だけ進行状況バーの値を Step インクリメントします。 このプロパティを Step 使用して、操作で完了した各タスクが進行状況バーの値を変更する量を指定できます。 たとえば、ファイルのグループをコピーする場合は、プロパティの Step 値を 1 に、プロパティの Maximum 値をコピーするファイルの合計数に設定できます。 各ファイルがコピーされると、メソッドを PerformStep 呼び出して、プロパティの値によって進行状況バーを Step インクリメントできます。 進行状況バーの値をより柔軟に制御する場合は、メソッドを Increment 使用するか、プロパティの値を Value 直接設定します。

このプロパティは ValueProgressBar. メソッドを呼び出した PerformStep 後、 Value プロパティがプロパティの Maximum 値より大きい場合、 Value プロパティはプロパティの値のまま Maximum です。 負の値を指定してメソッドをPerformStep呼び出した後、ValueStepプロパティがプロパティのMinimum値より小さい場合、Valueプロパティはプロパティの値のままMinimumです。

スタイルが ProgressBar 設定 Marquee されているオブジェクトの代わりに Value連続スクロール バーが表示されるため、呼び出し PerformStep は不要であり、 InvalidOperationException.

適用対象

こちらもご覧ください