次の方法で共有


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 コントロールを使用して、ファイル コピー操作の進行状況を表示します。 この例では、 Minimum プロパティと Maximum プロパティを使用して、コピーするファイルの数と等しい ProgressBar の範囲を指定します。 また、PerformStep メソッドと共に Step プロパティを使用して、ファイルのコピー時にProgressBarの値をインクリメントします。 この例では、Form内に作成されたpBar1と呼ばれるProgressBar コントロールを作成し、ファイル コピー操作を実行する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 プロパティの値を直接設定できます。

適用対象

こちらもご覧ください