EventDescriptor 類別

定義

提供事件的相關資訊。Provides information about an event.

public ref class EventDescriptor abstract : System::ComponentModel::MemberDescriptor
[System.Runtime.InteropServices.ComVisible(true)]
public abstract class EventDescriptor : System.ComponentModel.MemberDescriptor
type EventDescriptor = class
    inherit MemberDescriptor
Public MustInherit Class EventDescriptor
Inherits MemberDescriptor
繼承
EventDescriptor
屬性

範例

下列程式碼範例是以EventDescriptorCollection類別中的範例為基礎。The following code example is built upon the example in the EventDescriptorCollection class. 它會在文字方塊中的按鈕上, 列印每個事件的資訊 (類別、描述和顯示名稱)。It prints the information (category, description, and display name) of each event on a button in a text box. 它需要button1textbox1已經在表單上具現化。It requires that button1 and textbox1 have been instantiated on a form.

EventDescriptorCollection^ events = TypeDescriptor::GetEvents( button1 );

// Displays each event's information in the collection in a text box.
for each (EventDescriptor^ myEvent in events) {
    textBox1->Text += myEvent->Category + '\n';
    textBox1->Text += myEvent->Description + '\n';
    textBox1->Text += myEvent->DisplayName + '\n';
}
EventDescriptorCollection events = TypeDescriptor.GetEvents(button1);
// Displays each event's information in the collection in a text box.
foreach (System.ComponentModel.EventDescriptor myEvent in events) {
    textBox1.Text += myEvent.Category + '\n';
    textBox1.Text += myEvent.Description + '\n';
    textBox1.Text += myEvent.DisplayName + '\n';
}
Dim events As EventDescriptorCollection = TypeDescriptor.GetEvents(Button1)
' Displays each event's information in the collection in a text box.
Dim myEvent As EventDescriptor
For Each myEvent In events
    TextBox1.Text &= myEvent.Category & ControlChars.Cr
    TextBox1.Text &= myEvent.Description & ControlChars.Cr
    TextBox1.Text &= myEvent.DisplayName & ControlChars.Cr
Next myEvent

備註

EventDescriptor包含名稱、其屬性、事件所系結的元件、事件委派、委派類型, 以及委派是否為多播。An EventDescriptor consists of a name, its attributes, the component that the event is bound to, the event delegate, the type of delegate, and whether the delegate is multicast.

EventDescriptor提供下列abstract屬性和方法:EventDescriptor provides the following abstract properties and methods:

  • ComponentType包含此事件宣告所在的元件類型。ComponentType contains the type of the component this event is declared on.

  • EventType包含事件的委派類型。EventType contains the type of delegate for the event.

  • IsMulticast包含值, 指出事件委派是否為多播委派。IsMulticast contains a value indicating whether the event delegate is a multicast delegate.

  • AddEventHandler將事件系結至元件。AddEventHandler binds the event to a component.

  • RemoveEventHandler將委派從元件解除系結, 讓委派不再接收來自元件的事件。RemoveEventHandler unbinds the delegate from the component so that the delegate no longer receives events from the component.

如需事件的詳細資訊, 請參閱處理和引發事件For more information about events, see Handling and Raising Events. 如需反映的詳細資訊, 請參閱反映中的主題。For more information about reflection, see the topics in Reflection.

建構函式

EventDescriptor(MemberDescriptor)

使用指定 EventDescriptor 中的名稱和屬性,初始化 MemberDescriptor 類別的新執行個體。Initializes a new instance of the EventDescriptor class with the name and attributes in the specified MemberDescriptor.

EventDescriptor(MemberDescriptor, Attribute[])

使用指定 EventDescriptor 中的名稱,以及 MemberDescriptorMemberDescriptor 陣列中的屬性,初始化 Attribute 類別的新執行個體。Initializes a new instance of the EventDescriptor class with the name in the specified MemberDescriptor and the attributes in both the MemberDescriptor and the Attribute array.

EventDescriptor(String, Attribute[])

使用指定的名稱和屬性陣列,初始化 EventDescriptor 類別的新執行個體。Initializes a new instance of the EventDescriptor class with the specified name and attribute array.

屬性

AttributeArray

取得或設定屬性的陣列。Gets or sets an array of attributes.

(繼承來源 MemberDescriptor)
Attributes

取得這個成員的屬性集合。Gets the collection of attributes for this member.

(繼承來源 MemberDescriptor)
Category

取得成員所屬的分類名稱,如 CategoryAttribute 中所指定的。Gets the name of the category to which the member belongs, as specified in the CategoryAttribute.

(繼承來源 MemberDescriptor)
ComponentType

在衍生類別中覆寫時,取得這個事件所繫結的元件型別。When overridden in a derived class, gets the type of component this event is bound to.

Description

取得成員的描述,如 DescriptionAttribute 中所指定的。Gets the description of the member, as specified in the DescriptionAttribute.

(繼承來源 MemberDescriptor)
DesignTimeOnly

取得值,表示這個成員是否只在設計階段設定,如 DesignOnlyAttribute 中所指定的。Gets whether this member should be set only at design time, as specified in the DesignOnlyAttribute.

(繼承來源 MemberDescriptor)
DisplayName

取得可在視窗 (例如 [屬性] 視窗) 中顯示的名稱。Gets the name that can be displayed in a window, such as a Properties window.

(繼承來源 MemberDescriptor)
EventType

在衍生類別中覆寫時,取得事件的委派型別。When overridden in a derived class, gets the type of delegate for the event.

IsBrowsable

取得值,表示成員是否可瀏覽,如 BrowsableAttribute 中指定的。Gets a value indicating whether the member is browsable, as specified in the BrowsableAttribute.

(繼承來源 MemberDescriptor)
IsMulticast

在衍生類別中覆寫時,取得指示事件委派是否為多點傳送委派的值。When overridden in a derived class, gets a value indicating whether the event delegate is a multicast delegate.

Name

取得成員的名稱。Gets the name of the member.

(繼承來源 MemberDescriptor)
NameHashCode

取得成員名稱的雜湊程式碼,如 GetHashCode() 中所指定的。Gets the hash code for the name of the member, as specified in GetHashCode().

(繼承來源 MemberDescriptor)

方法

AddEventHandler(Object, Delegate)

在衍生類別中覆寫時,將事件繫結至元件。When overridden in a derived class, binds the event to the component.

CreateAttributeCollection()

使用傳遞給建構函式的屬性陣列,建立屬性的集合。Creates a collection of attributes using the array of attributes passed to the constructor.

(繼承來源 MemberDescriptor)
Equals(Object)

比較這個執行個體和指定的物件,以檢視它們是否相等。Compares this instance to the given object to see if they are equivalent.

(繼承來源 MemberDescriptor)
FillAttributes(IList)

當在衍生類別中覆寫時,將繼承類別的屬性加入父類別中屬性的指定清單。When overridden in a derived class, adds the attributes of the inheriting class to the specified list of attributes in the parent class.

(繼承來源 MemberDescriptor)
GetHashCode()

傳回這個執行個體的雜湊碼。Returns the hash code for this instance.

(繼承來源 MemberDescriptor)
GetInvocationTarget(Type, Object)

擷取應該在成員的引動過程使用的物件。Retrieves the object that should be used during invocation of members.

(繼承來源 MemberDescriptor)
GetType()

取得目前執行個體的 TypeGets the Type of the current instance.

(繼承來源 Object)
MemberwiseClone()

建立目前 Object 的淺層複製。Creates a shallow copy of the current Object.

(繼承來源 Object)
RemoveEventHandler(Object, Delegate)

在衍生類別中覆寫時,將委派與元件解除繫結,以便委派不再接收來自元件的事件。When overridden in a derived class, unbinds the delegate from the component so that the delegate will no longer receive events from the component.

ToString()

傳回代表目前物件的字串。Returns a string that represents the current object.

(繼承來源 Object)

適用於

另請參閱