Control.Events 屬性

定義

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

protected:
 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.

適用於

另請參閱