Control.Events 属性


获取控件的事件处理程序委托列表。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.