Control.OnTabStopChanged(EventArgs) メソッド
重要
一部の情報は、リリース前に大きく変更される可能性があるプレリリースされた製品に関するものです。 Microsoft は、ここに記載されている情報について、明示または黙示を問わず、一切保証しません。
TabStopChanged イベントを発生させます。
protected:
virtual void OnTabStopChanged(EventArgs ^ e);
protected virtual void OnTabStopChanged(EventArgs e);
abstract member OnTabStopChanged : EventArgs -> unit
override this.OnTabStopChanged : EventArgs -> unit
Protected Overridable Sub OnTabStopChanged (e As EventArgs)
次のコード例は、プロパティ値が変更されたときに Text 実行されるイベント発生メソッドです。
Controlクラスには、PropertyName の値が変更されたときに対応する PropertyName イベントを発生させる名前パターン On
PropertyNameChanged
Changed
を持ついくつかのメソッドがあります (PropertyName は、対応するプロパティの名前を表します)。
次のコード例では、通貨データを ForeColor 表示する TextBox 派生クラスの を変更します。 この例では、テキストを 10 進数に変換し、数値が負の場合は にColor.Red、数値が正の場合は を にColor.Black変更ForeColorします。 この例では、 クラスから TextBox 派生したクラスが必要です。
protected:
virtual void OnTextChanged( System::EventArgs^ e ) override
{
try
{
// Convert the text to a Double and determine
// if it is a negative number.
if ( Double::Parse( this->Text ) < 0 )
{
// If the number is negative, display it in Red.
this->ForeColor = Color::Red;
}
else
{
// If the number is not negative, display it in Black.
this->ForeColor = Color::Black;
}
}
catch ( Exception^ )
{
// If there is an error, display the
// text using the system colors.
this->ForeColor = SystemColors::ControlText;
}
TextBox::OnTextChanged( e );
}
protected override void OnTextChanged(System.EventArgs e)
{
try
{
// Convert the text to a Double and determine
// if it is a negative number.
if(double.Parse(this.Text) < 0)
{
// If the number is negative, display it in Red.
this.ForeColor = Color.Red;
}
else
{
// If the number is not negative, display it in Black.
this.ForeColor = Color.Black;
}
}
catch
{
// If there is an error, display the
// text using the system colors.
this.ForeColor = SystemColors.ControlText;
}
base.OnTextChanged(e);
}
Protected Overrides Sub OnTextChanged(e As System.EventArgs)
Try
' Convert the text to a Double and determine
' if it is a negative number.
If Double.Parse(Me.Text) < 0 Then
' If the number is negative, display it in Red.
Me.ForeColor = Color.Red
Else
' If the number is not negative, display it in Black.
Me.ForeColor = Color.Black
End If
Catch
' If there is an error, display the
' text using the system colors.
Me.ForeColor = SystemColors.ControlText
End Try
MyBase.OnTextChanged(e)
End Sub
イベントを発生させると、イベント ハンドラーがデリゲートから呼び出されます。 詳細については、処理とイベントの発生 を参照してください。
メソッドを OnTabStopChanged 使用すると、デリゲートをアタッチせずに、派生クラスでイベントを処理することもできます。 派生クラスでイベントを処理する場合は、この手法をお勧めします。
派生クラスで OnTabStopChanged(EventArgs) をオーバーライドする場合は、登録されているデリゲートがイベントを受け取ることができるように、基本クラスの OnTabStopChanged(EventArgs) メソッドを呼び出してください。
製品 | バージョン |
---|---|
.NET Framework | 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1 |
Windows Desktop | 3.0, 3.1, 5, 6, 7, 8, 9, 10 |
.NET に関するフィードバック
.NET はオープンソース プロジェクトです。 フィードバックを提供するにはリンクを選択します。