ToolStripControlHost.OnUnsubscribeControlEvents(Control) 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
取消訂閱託管控制的事件。
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) ,讓註冊代理接收事件。