Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

EventDescriptor Class

Provides information about an event.

For a list of all members of this type, see EventDescriptor Members.

System.Object
   System.ComponentModel.MemberDescriptor
      System.ComponentModel.EventDescriptor

[Visual Basic]
<ComVisible(True)>
MustInherit Public Class EventDescriptor
   Inherits MemberDescriptor
[C#]
[ComVisible(true)]
public abstract class EventDescriptor : MemberDescriptor
[C++]
[ComVisible(true)]
public __gc __abstract class EventDescriptor : public
   MemberDescriptor
[JScript]
public
   ComVisible(true)
abstract class EventDescriptor extends MemberDescriptor

Thread Safety

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Remarks

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 provides the following abstract (MustOverride in Visual Basic) properties and methods:

  • ComponentType contains the type of the component this event is declared on.
  • EventType contains the type of delegate for the event.
  • IsMulticast contains a value indicating whether the event delegate is a multicast delegate.
  • AddEventHandler binds the event to a component.
  • RemoveEventHandler unbinds the delegate from the component so that the delegate no longer receives events from the component.

For more information on events, see Raising an Event. For more information about reflection, see Discovering Type Information at Run Time.

Example

[Visual Basic, C#, C++] The following example is built upon the example in the EventDescriptorCollection class. It prints the information (category, description, display name) of each event on a button in a text box. It assumes that button1 and textbox1 have been instantiated on a form.

[Visual Basic] 
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

[C#] 
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';
}

[C++] 
EventDescriptorCollection* events = TypeDescriptor::GetEvents(button1);
// Displays each event's information in the collection in a text box.
IEnumerator* myEnum = events->GetEnumerator();
while (myEnum->MoveNext())
{
   EventDescriptor* myEvent = __try_cast<EventDescriptor*>(myEnum->Current);
   textBox1->Text = String::Concat( textBox1->Text, myEvent->Category, S"\n" );
   textBox1->Text = String::Concat( textBox1->Text, myEvent->Description, S"\n" );
   textBox1->Text = String::Concat( textBox1->Text, myEvent->DisplayName, S"\n" );
}

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Namespace: System.ComponentModel

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, .NET Compact Framework

Assembly: System (in System.dll)

See Also

EventDescriptor Members | System.ComponentModel Namespace | MemberDescriptor | Attribute

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.