ToolStripControlHost.OnUnsubscribeControlEvents(Control) メソッド

定義

ホストされているコントロールからのイベントのサブスクライブを解除します。

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

パラメーター

control
Control

イベントのサブスクライブを解除するコントロール。

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

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

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

    // Remove the event.
    monthCalendarControl.DateChanged -=
        new DateRangeEventHandler(OnDateChanged);
}
Protected Overrides Sub OnUnsubscribeControlEvents(ByVal c As Control)
    ' Call the base method so the basic events are unsubscribed.
    MyBase.OnUnsubscribeControlEvents(c)

    ' Cast the control to a MonthCalendar control.
    Dim monthCalendarControl As MonthCalendar = _
        CType(c, MonthCalendar)

    ' Remove the event.
    RemoveHandler monthCalendarControl.DateChanged, _
        AddressOf HandleDateChanged

End Sub

注釈

OnUnsubscribeControlEvents メソッドをオーバーライドして、OnSubscribeControlEventsでサブスクライブされているイベントのサブスクライブを解除します。

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

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

注意 (継承者)

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

適用対象