Component.CanRaiseEvents 屬性


取得值,指出元件是否能引發事件。Gets a value indicating whether the component can raise an event.

 virtual property bool CanRaiseEvents { bool get(); };
protected virtual bool CanRaiseEvents { get; }
member this.CanRaiseEvents : bool
Protected Overridable ReadOnly Property CanRaiseEvents As Boolean


如果元件可以引發事件,則為 true,否則為 falsetrue if the component can raise events; otherwise, false. 預設為 trueThe default is true.


這個屬性的預設實值一律true會傳回。The default implementation of this property always returns true. 繼承自Component類別的類別應該覆寫這個屬性, 以提供停用引發事件的功能。Classes that inherit from the Component class should override this property to provide the ability to disable the raising of events. 例如, 在Control類別中, 如果控制項裝載為 activex 控制項CanRaiseEvents , false當 activex 控制項的事件凍結時, 屬性會傳回。For example, in the Control class, if the control is being hosted as an ActiveX control, the CanRaiseEvents property returns false if the ActiveX control has its events frozen.


如果您在衍生類別中覆寫這個方法, 並將它false變更為EventHandlerList null傳回, 則Events屬性傳回的集合會針對事件傳回。If you override this method in a deriving class and change it to return false, the EventHandlerList collection returned by the Events property returns null for an event. 事件仍然可以從集合中加入和移除, 但是集合的Item[Object]屬性null一律會傳回。Events can still be added and removed from the collection, but the collection's Item[Object] property will always return null.