Control.Events Control.Events Control.Events Control.Events Property


取得控制項事件處理常式委派 (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.

請注意如何控制項中新增和移除事件的清單,這些控制項會維護,此範例中會最佳化。Note 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.