ProgressBar.Maximum プロパティ
アセンブリ: System.Windows.Forms (system.windows.forms.dll 内)
構文
範囲の最大値。既定値は 100 です。
解説
このプロパティは Value プロパティの上限値を指定します。Maximum プロパティの値が変更されると、ProgressBar コントロールは新しい範囲を反映して再描画されます。Value プロパティの値が Maximum プロパティの値に等しくなると、プログレス バーは完全に塗りつぶされます。
このプロパティを使用すると、操作が完了したことを示すために、Value プロパティを設定するか、Increment メソッドまたは PerformStep メソッドを使用して、Value プロパティに指定する必要のある値を指定できます。たとえば、Maximum プロパティの値を 1 回のファイル コピー操作におけるファイルの合計数に設定できます。ファイルをコピーするたびに、Value プロパティの値は、合計数分のファイルがコピーされるまで、1 ずつ増加されます。合計数に達した時点で、プログレス バーは完全に塗りつぶされます。
ProgressBar コントロールを使用して、ファイルのコピー操作の進行状況を表示するコード例を次に示します。この例では、Minimum プロパティおよび Maximum プロパティを使用して、コピーするファイル数に相当する ProgressBar の範囲を指定しています。このコードでは、ファイルのコピー時に ProgressBar の値をインクリメントするために、PerformStep メソッドと Step プロパティも使用します。この例では、Form 内に pBar1 という ProgressBar コントロールが作成されており、ファイルのコピー操作を実行し、操作が正常終了したことを示すブール値を返す CopyFile というメソッドが作成されている必要があります。また、コピー対象のファイルを含む文字列の配列が作成され、この例の中で定義されている CopyWithProgress メソッドにその配列が渡されており、そのメソッドが Form の別のメソッドまたはイベントから呼び出される必要もあります。
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
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: 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.set_Visible(true); // Set Minimum to 1 to represent the first file being copied. pBar1.set_Minimum(1); // Set Maximum to the total number of files to copy. pBar1.set_Maximum(fileNames.get_Length()); // Set the initial value of the ProgressBar. pBar1.set_Value(1); // Set the Step property to a value of 1 to represent each file // being copied. pBar1.set_Step(1); // Loop through all files to copy. for (int x = 1; x <= fileNames.get_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(); } } } //CopyWithProgress
Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。
参照
- ProgressBar.Maximum プロパティのページへのリンク