Export (0) Print
Expand All

EventDescriptorCollection Class

Represents a collection of EventDescriptor objects.

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

System.Object
   System.ComponentModel.EventDescriptorCollection

[Visual Basic]
<ComVisible(True)>
Public Class EventDescriptorCollection
   Implements IList, ICollection, IEnumerable
[C#]
[ComVisible(true)]
public class EventDescriptorCollection : IList, ICollection,
   IEnumerable
[C++]
[ComVisible(true)]
public __gc class EventDescriptorCollection : public IList,
   ICollection, IEnumerable
[JScript]
public
   ComVisible(true)
class EventDescriptorCollection implements IList,
   ICollection, IEnumerable

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

EventDescriptorCollection is read-only; it does not implement methods that add or remove events. You must inherit from this class to implement these methods.

Using the properties available in the EventDescriptorCollection class, you can query the collection about its contents. Use the Count property to determine the number of elements in the collection. Use the Item property to get a specific property by index number or by name.

You can also use the Find method to get a description of the event with the specified name from the collection.

Example

[Visual Basic, C#, C++] The following example prints all the events on a button in a text box. It assumes that button1 and textBox1 have been instantiated on a form.

[Visual Basic] 
Private Sub MyEventCollection()
    ' Creates a new collection and assigns it the events for button1.
    Dim events As EventDescriptorCollection = TypeDescriptor.GetEvents(button1)
    
    ' Displays each event in the collection in a text box.
    Dim myEvent As EventDescriptor
    For Each myEvent In  events
        textBox1.Text &= myEvent.Name & ControlChars.Cr
    Next myEvent
End Sub 'MyEventCollection 

[C#] 
private void MyEventCollection() {
    // Creates a new collection and assigns it the events for button1.
    EventDescriptorCollection events = TypeDescriptor.GetEvents(button1);
 
    // Displays each event in the collection in a text box.
    foreach (EventDescriptor myEvent in events)
       textBox1.Text += myEvent.Name + '\n';
 }


[C++] 
private:
    void MyEventCollection() {
        // Creates a new collection and assigns it the events for button1.
        EventDescriptorCollection* events = TypeDescriptor::GetEvents(button1);

        // Displays each event in the collection in a text box.
        System::Collections::IEnumerator* myEnum = events->GetEnumerator();
        while (myEnum->MoveNext())
        {
            EventDescriptor* myEvent = __try_cast<EventDescriptor*>(myEnum->Current);
            textBox1->Text = String::Concat( textBox1->Text, myEvent->Name, 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

EventDescriptorCollection Members | System.ComponentModel Namespace | EventDescriptor | TypeDescriptor

Show:
© 2014 Microsoft