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) 委托接收事件。

适用于