Control.OnContextMenuChanged(EventArgs) メソッド

定義

ContextMenuChanged イベントを発生させます。

protected:
 virtual void OnContextMenuChanged(EventArgs ^ e);
protected virtual void OnContextMenuChanged (EventArgs e);
abstract member OnContextMenuChanged : EventArgs -> unit
override this.OnContextMenuChanged : EventArgs -> unit
Protected Overridable Sub OnContextMenuChanged (e As EventArgs)

パラメーター

e
EventArgs

イベント データを格納している EventArgs

次のコード例は、プロパティ値が変更されたときに Text 実行されるイベント発生メソッドです。 Controlクラスには、PropertyName の値が変更されたときに対応する PropertyNameChanged イベントを発生させる名前パターン OnPropertyNameChanged を持ついくつかのメソッドがあります (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

注釈

イベントを発生させると、イベント ハンドラーがデリゲートから呼び出されます。 詳細については、処理とイベントの発生 を参照してください。

OnContextMenuChanged メソッドを使用すると、デリゲートを結び付けずに、派生クラスでイベントを処理することもできます。 派生クラスでイベントを処理する場合は、この手法をお勧めします。

注意 (継承者)

派生クラスで OnContextMenuChanged(EventArgs) をオーバーライドする場合は、登録されているデリゲートがイベントを受け取ることができるように、基本クラスの OnContextMenuChanged(EventArgs) メソッドを呼び出してください。

適用対象

こちらもご覧ください