EventDescriptorCollection::GetEnumerator Method ()

 

Gets an enumerator for this EventDescriptorCollection.

Namespace:   System.ComponentModel
Assembly:  System (in System.dll)

public:
IEnumerator^ GetEnumerator()

Return Value

Type: System.Collections::IEnumerator^

An enumerator that implements IEnumerator.

System_CAPS_noteNote

The HostProtectionAttribute attribute applied to this class has the following Resources property value: Synchronization. The HostProtectionAttribute does not affect desktop applications (which are typically started by double-clicking an icon, typing a command, or entering a URL in a browser). For more information, see the HostProtectionAttribute class or SQL Server Programming and Host Protection Attributes.

The following code example gets an enumerator for the events on button1. It uses the enumerator to print the names of the events in the collection. It requires that button1 and textBox1 have been instantiated on a form.

private:
   void MyEnumerator()
   {
      // Creates a new collection, and assigns to it the events for button1.
      EventDescriptorCollection^ events = TypeDescriptor::GetEvents( button1 );

      // Creates an enumerator.
      IEnumerator^ ie = events->GetEnumerator();

      // Prints the name of each event in the collection.
      Object^ myEvent;
      while ( ie->MoveNext() == true )
      {
         myEvent = ie->Current;
         textBox1->Text = String::Concat( textBox1->Text, myEvent, "\n" );
      }
   }

.NET Framework
Available since 1.1
Return to top
Show: