Control.OnParentForeColorChanged メソッド
アセンブリ: System.Windows.Forms (system.windows.forms.dll 内)

Dim e As EventArgs Me.OnParentForeColorChanged(e)

イベントが発生すると、デリゲートを使用してイベント ハンドラが呼び出されます。詳細については、「イベントの発生」を参照してください。
OnParentForeColorChanged メソッドを使用すると、デリゲートを結び付けずに、派生クラスでイベントを処理することもできます。派生クラスでイベントを処理する場合は、この手法をお勧めします。
継承時の注意 派生クラスで OnParentForeColorChanged をオーバーライドする場合は、登録されているデリゲートがイベントを受け取ることができるように、基本クラスの OnParentForeColorChanged メソッドを呼び出してください。
Text プロパティの値が変更されたときに実行されるイベント発生メソッドのコード例を次に示します。Control クラスには、OnPropertyNameChanged という名前のパターンを持つメソッドがいくつかあります。これらは、PropertyName 値が変更されたときに対応する PropertyNameChanged イベントを発生させます。ここで、PropertyName は対応するプロパティの名前を表します。
通貨型のデータを表示する TextBox の派生クラスの ForeColor を変更するコード例を次に示します。テキストを 10 進数に変換し、値が負の場合は ForeColor を Color.Red に変更し、正の場合は Color.Black に変更する例を次に示します。この例では、TextBox クラスから派生したクラスが存在している必要があります。
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
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: 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 void OnTextChanged(System.EventArgs e) { try { // Convert the text to a Double and determine // if it is a negative number. if (System.Double.Parse(this.get_Text()) < 0) { // If the number is negative, display it in Red. this.set_ForeColor(Color.get_Red()); } else { // If the number is not negative, display it in Black. this.set_ForeColor(Color.get_Black()); } } catch (System.Exception exp) { // If there is an error, display the // text using the system colors. this.set_ForeColor(SystemColors.get_ControlText()); } super.OnTextChanged(e); } //OnTextChanged

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 によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


Weblioに収録されているすべての辞書からControl.OnParentForeColorChanged メソッドを検索する場合は、下記のリンクをクリックしてください。

- Control.OnParentForeColorChanged メソッドのページへのリンク