ToolStripControlHost.OnUnsubscribeControlEvents(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) 方法,以便已注册的委托对事件进行接收。

适用于