次の方法で共有


EventDescriptorCollection.GetEnumerator メソッド

定義

この EventDescriptorCollectionの列挙子を取得します。

public:
 System::Collections::IEnumerator ^ GetEnumerator();
public:
 virtual System::Collections::IEnumerator ^ GetEnumerator();
public System.Collections.IEnumerator GetEnumerator();
member this.GetEnumerator : unit -> System.Collections.IEnumerator
abstract member GetEnumerator : unit -> System.Collections.IEnumerator
override this.GetEnumerator : unit -> System.Collections.IEnumerator
Public Function GetEnumerator () As IEnumerator

戻り値

IEnumeratorを実装する列挙子。

実装

次のコード例では、 button1のイベントの列挙子を取得します。 列挙子を使用して、コレクション内のイベントの名前を出力します。 フォームで button1textBox1 がインスタンス化されている必要があります。

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() )
      {
         myEvent = ie->Current;
         textBox1->Text = String::Concat( textBox1->Text, myEvent, "\n" );
      }
   }
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())
    {
        myEvent = ie.Current;
        textBox1.Text += myEvent.ToString() + '\n';
    }
}
Private Sub MyEnumerator()
    ' Creates a new collection, and assigns to it the events for button1.
    Dim events As EventDescriptorCollection = TypeDescriptor.GetEvents(button1)
    
    ' Creates an enumerator.
    Dim ie As IEnumerator = events.GetEnumerator()
    
    ' Prints the name of each event in the collection.
    Dim myEvent As Object
    While ie.MoveNext() = True
        myEvent = ie.Current
        textBox1.Text += myEvent.ToString() & ControlChars.Cr
    End While
End Sub

注釈

このクラスに適用される HostProtectionAttribute 属性には、次の Resources プロパティ値があります: SynchronizationHostProtectionAttributeはデスクトップ アプリケーションには影響しません (通常、アイコンをダブルクリックするか、コマンドを入力するか、ブラウザーで URL を入力します)。 詳細については、 HostProtectionAttribute クラスまたは SQL Server プログラミング属性とホスト保護属性に関するページを参照してください。

適用対象

こちらもご覧ください