ToolStripControlHost.OnSubscribeControlEvents(Control) メソッド

定義

ホストされたコントロールからイベントをサブスクライブします。

protected:
 virtual void OnSubscribeControlEvents(System::Windows::Forms::Control ^ control);
protected virtual void OnSubscribeControlEvents(System.Windows.Forms.Control control);
abstract member OnSubscribeControlEvents : System.Windows.Forms.Control -> unit
override this.OnSubscribeControlEvents : System.Windows.Forms.Control -> unit
Protected Overridable Sub OnSubscribeControlEvents (control As Control)

パラメーター

control
Control

イベントのサブスクライブ元となるコントロール。

次のコード例は、ホストされたコントロールによって公開されるイベントのイベント処理を設定する方法を示しています。 このコード例は、 ToolStripControlHost クラスに提供されるより大きな例の一部です。

void OnSubscribeControlEvents( System::Windows::Forms::Control^ c )
{
   // Call the base so the base events are connected.
   __super::OnSubscribeControlEvents( c );
   
   // Cast the control to a MonthCalendar control.
   MonthCalendar^ monthCalendarControl = (MonthCalendar^)c;
   
   // Add the event.
   monthCalendarControl->DateChanged += gcnew DateRangeEventHandler( this, &ToolStripMonthCalendar::HandleDateChanged );
}
protected override void OnSubscribeControlEvents(Control c)
{
    // Call the base so the base events are connected.
    base.OnSubscribeControlEvents(c);

    // Cast the control to a MonthCalendar control.
    MonthCalendar monthCalendarControl = (MonthCalendar) c;

    // Add the event.
    monthCalendarControl.DateChanged +=
        new DateRangeEventHandler(OnDateChanged);
}
Protected Overrides Sub OnSubscribeControlEvents(ByVal c As Control) 

    ' Call the base so the base events are connected.
    MyBase.OnSubscribeControlEvents(c)
    
    ' Cast the control to a MonthCalendar control.
    Dim monthCalendarControl As MonthCalendar = _
        CType(c, MonthCalendar)

    ' Add the event.
    AddHandler monthCalendarControl.DateChanged, _
        AddressOf HandleDateChanged

End Sub

注釈

コントロール イベントの同期を追加または禁止するには、 OnSubscribeControlEvents メソッドをオーバーライドします。

ここでイベントをオーバーライドしてフックする場合は、 OnUnsubscribeControlEvents メソッドを使用してイベントのフックを解除します。

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

OnSubscribeControlEvents メソッドでは、デリゲートをアタッチせずに、派生クラスでイベントを処理することもできます。 これは、派生クラスでイベントを処理するために推奨される手法です。

注意 (継承者)

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

適用対象