ToolStripControlHost.OnSubscribeControlEvents(Control) 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
訂閱託管控制區的事件。
protected:
virtual void OnSubscribeControlEvents(System::Windows::Forms::Control ^ control);
protected virtual void OnSubscribeControlEvents(System.Windows.Forms.Control control);
protected virtual void OnSubscribeControlEvents(System.Windows.Forms.Control? control);
abstract member OnSubscribeControlEvents : System.Windows.Forms.Control -> unit
override this.OnSubscribeControlEvents : System.Windows.Forms.Control -> unit
Protected Overridable Sub OnSubscribeControlEvents (control As Control)
參數
- control
- Control
訂閱事件的控制權。
範例
以下程式碼範例示範如何為託管控制所暴露的事件設定事件處理。 此程式碼範例是本類別更大範例 ToolStripControlHost 的一部分。
void OnSubscribeControlEvents( System::Windows::Forms::Control^ c )
{
// Call the base so the base events are connected.
__super::OnSubscribeControlEvents( c );
// Cast the control to a MonthCalendar control.
MonthCalendar^ monthCalendarControl = (MonthCalendar^)c;
// Add the event.
monthCalendarControl->DateChanged += gcnew DateRangeEventHandler( this, &ToolStripMonthCalendar::HandleDateChanged );
}
protected override void OnSubscribeControlEvents(Control c)
{
// Call the base so the base events are connected.
base.OnSubscribeControlEvents(c);
// Cast the control to a MonthCalendar control.
MonthCalendar monthCalendarControl = (MonthCalendar) c;
// Add the event.
monthCalendarControl.DateChanged +=
new DateRangeEventHandler(OnDateChanged);
}
Protected Overrides Sub OnSubscribeControlEvents(ByVal c As Control)
' Call the base so the base events are connected.
MyBase.OnSubscribeControlEvents(c)
' Cast the control to a MonthCalendar control.
Dim monthCalendarControl As MonthCalendar = _
CType(c, MonthCalendar)
' Add the event.
AddHandler monthCalendarControl.DateChanged, _
AddressOf HandleDateChanged
End Sub
備註
覆寫新增 OnSubscribeControlEvents 或阻止控制事件同步的方法。
如果你在這邊覆寫並連接事件,請用這個 OnUnsubscribeControlEvents 方法解除掛鉤。
發起事件會透過代理呼叫事件處理者。 欲了解更多資訊,請參閱 處理與提升事件。
此 OnSubscribeControlEvents 方法也允許衍生類別在不附加代理的情況下處理事件。 這是在衍生類別中處理事件的首選技術。
給繼承者的注意事項
在導出類別中覆寫 OnSubscribeControlEvents(Control) 時,務必呼叫基底類別的方法 OnSubscribeControlEvents(Control) ,讓註冊代理接收事件。