Control.Events 屬性


取得控制項事件處理常式委派 (Delegate) 的清單。Gets a list of event handler delegates for the control. 這個屬性是唯讀的。This property is read-only.

 property System::ComponentModel::EventHandlerList ^ Events { System::ComponentModel::EventHandlerList ^ get(); };
protected System.ComponentModel.EventHandlerList Events { get; }
member this.Events : System.ComponentModel.EventHandlerList
Protected ReadOnly Property Events As EventHandlerList



事件處理常式委派的清單。The list of event handler delegates.


下列範例會建立名為的事件, Click EventHandlerList 當從頁面呼叫事件時,會在控制項的集合中加入和移除處理常式。The following example creates an event, named Click, that adds and removes handlers from the control's EventHandlerList collection when the event is called from a page.


這個範例會將控制項在控制項所維護的清單中新增和移除事件的方式優化。This example optimizes how a control adds and removes events from the list of them that the control maintains. 如果您建立自訂控制項,而且想要定義事件,請使用與此類似的程式碼。If you create custom control and want to define an event, use code similar to this. 這項技術可用於 c #,但不能在 Visual Basic 中使用。This technique can be used in C#, but not in Visual Basic.

// Create an event that adds and removes handlers from the
// Control.Events collection when this event is called from
// a participating page.
public event EventHandler Click {
    add {
        Events.AddHandler(EventClick, value);
    remove {
        Events.RemoveHandler(EventClick, value);


這個屬性的型別是 EventHandlerList ,它會使用線性搜尋演算法來尋找委派清單中的專案。This property is of type EventHandlerList, which uses a linear search algorithm to find entries in the list of delegates. 使用大量專案時,線性搜尋演算法沒有效率。A linear search algorithm is inefficient when working with a large number of entries. 因此,當您有大型清單時,尋找具有此屬性的專案將會變慢。Therefore, when you have a large list, finding entries with this property will be slow.