Component.CanRaiseEvents Property


取得值,指出元件是否能引發事件。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

Property Value


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


這個屬性的預設實值一律會傳回 trueThe 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 控制項,則如果 ActiveX 控制項的事件已凍結,則 CanRaiseEvents 屬性會傳回 falseFor 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.

Notes to Inheritors

如果您在衍生類別中覆寫這個方法,並將它變更為傳回 false,則 Events 屬性傳回的 EventHandlerList 集合會針對事件傳回 nullIf 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] 屬性一律會傳回 nullEvents can still be added and removed from the collection, but the collection's Item[Object] property will always return null.

Applies to

See also