Control.Events 屬性

定義

取得控制項事件處理常式委派 (Delegate) 的清單。 這個屬性是唯讀的。

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 集合中新增和移除處理常式。

注意

此範例會優化控制項如何從控制項所維護的事件清單中新增和移除事件。 如果您建立自訂控制項並想要定義事件,請使用類似以下的程式碼。 這項技術可以在 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 為 ,它會使用線性搜尋演算法來尋找委派清單中的專案。 使用大量專案時,線性搜尋演算法效率不佳。 因此,當您有大型清單時,尋找具有此屬性的專案將會很慢。

適用於

另請參閱