共用方式為


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) 方法,使已註冊的委派能接收到事件。

適用於