Control.Events 屬性
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
會取得一個事件處理代理清單來管理控制。 這個屬性是唯讀的。
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
屬性值
事件處理代理的名單。
範例
以下範例會建立一個事件,名為 Click,當事件從頁面呼叫時,會從控制項 EventHandlerList 集合中新增或移除處理器。
Note
此範例優化控制項如何新增或移除其維護的事件清單。 如果你建立自訂控制並想定義事件,可以用類似這樣的程式碼。 此技巧可在 C# 中使用,但不適用於 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,利用線性搜尋演算法尋找代理列表中的條目。 線性搜尋演算法在處理大量條目時效率不高。 因此,當你的清單很大時,找到符合這個屬性的條目會比較慢。