ProgressBar.Increment メソッド
アセンブリ: System.Windows.Forms (system.windows.forms.dll 内)
構文
例外
解説
Increment メソッドを使用すると、指定した量だけプログレス バーの値をインクリメントできます。このメソッドによるプログレス バーのインクリメントは、PerformStep メソッドで Step プロパティを使用する方法と似ています。Value プロパティは、ProgressBar の現在位置を指定します。Increment メソッドを呼び出した後で、Value プロパティが Maximum プロパティの値を超える場合、Value プロパティは Maximum プロパティの値のままになります。value パラメータに負の値を指定して Increment メソッドを呼び出した後に、Value プロパティが Minimum プロパティの値未満になった場合、Value プロパティは Minimum プロパティの値のままになります。
Increment メソッドと Value プロパティを使用して、Timer の Tick イベントで ProgressBar の値をインクリメントするコード例を次に示します。またこの例では、StatusBarPanel に Value プロパティを表示して、ProgressBar をテキストで表します。この例では、progressBar1 という名前の ProgressBar コントロール、および statusBarPanel1 という名前の StatusBarPanel が配置された StatusBar コントロールが存在する必要があります。また、time という名前の Timer を、メンバとしてフォームに追加する必要があります。
Private time As New Timer() ' Call this method from the constructor of the form. Private Sub InitializeMyTimer() ' Set the interval for the timer. time.Interval = 250 ' Connect the Tick event of the timer to its event handler. AddHandler time.Tick, AddressOf IncreaseProgressBar ' Start the timer. time.Start() End Sub Private Sub IncreaseProgressBar(ByVal sender As Object, ByVal e As EventArgs) ' Increment the value of the ProgressBar a value of one each time. ProgressBar1.Increment(1) ' Display the textual value of the ProgressBar in the StatusBar control's first panel. statusBarPanel1.Text = ProgressBar1.Value.ToString() + "% Completed" ' Determine if we have completed by comparing the value of the Value property to the Maximum value. If ProgressBar1.Value = ProgressBar1.Maximum Then ' Stop the timer. time.Stop() End If End Sub
private Timer time = new Timer(); // Call this method from the constructor of the form. private void InitializeMyTimer() { // Set the interval for the timer. time.Interval = 250; // Connect the Tick event of the timer to its event handler. time.Tick += new EventHandler(IncreaseProgressBar); // Start the timer. time.Start(); } private void IncreaseProgressBar(object sender, EventArgs e) { // Increment the value of the ProgressBar a value of one each time. progressBar1.Increment(1); // Display the textual value of the ProgressBar in the StatusBar control's first panel. statusBarPanel1.Text = progressBar1.Value.ToString() + "% Completed"; // Determine if we have completed by comparing the value of the Value property to the Maximum value. if (progressBar1.Value == progressBar1.Maximum) // Stop the timer. time.Stop(); }
private: Timer^ time; // Call this method from the constructor of the form. void InitializeMyTimer() { // Set the interval for the timer. time->Interval = 250; // Connect the Tick event of the timer to its event handler. time->Tick += gcnew EventHandler( this, &Form1::IncreaseProgressBar ); // Start the timer. time->Start(); } void IncreaseProgressBar( Object^ /*sender*/, EventArgs^ /*e*/ ) { // Increment the value of the ProgressBar a value of one each time. progressBar1->Increment( 1 ); // Display the textual value of the ProgressBar in the StatusBar control's first panel. statusBarPanel1->Text = String::Concat( progressBar1->Value, "% Completed" ); // Determine if we have completed by comparing the value of the Value property to the Maximum value. if ( progressBar1->Value == progressBar1->Maximum ) // Stop the timer. time->Stop(); }
private Timer time = new Timer(); // Call this method from the constructor of the form. private void InitializeMyTimer() { // Set the interval for the timer. time.set_Interval(250); // Connect the Tick event of the timer to its event handler. time.add_Tick(new EventHandler(IncreaseProgressBar)); // Start the timer. time.Start(); } //InitializeMyTimer private void IncreaseProgressBar(Object sender, EventArgs e) { // Increment the value of the ProgressBar a value of one each time. progressBar1.Increment(1); // Display the textual value of the ProgressBar in the StatusBar // control's first panel. statusBarPanel1.set_Text(progressBar1.get_Value() + "% Completed"); // Determine if we have completed by comparing the value of the Value // property to the Maximum value. if (progressBar1.get_Value() == progressBar1.get_Maximum()) { // Stop the timer. time.Stop(); } } //IncreaseProgressBar
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.Increment メソッドのページへのリンク