次の方法で共有


EventDescriptorCollection クラス

EventDescriptor オブジェクトのコレクションを表します。

この型のすべてのメンバの一覧については、EventDescriptorCollection メンバ を参照してください。

System.Object
   System.ComponentModel.EventDescriptorCollection

<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

スレッドセーフ

この型の public static (Visual Basicでは Shared) のすべてのメンバは、マルチスレッド操作で安全に使用できます。インスタンスのメンバの場合は、スレッドセーフであるとは限りません。

解説

EventDescriptorCollection は読み取り専用であり、イベントを追加または削除するためのメソッドは実装していません。これらのメソッドを実装するには、このクラスから継承する必要があります。

EventDescriptorCollection クラスで利用できるプロパティを使用して、コレクションに対してその内容を照会できます。コレクション内の要素の数を確認するには、 Count プロパティを使用します。インデックス番号または名前で指定したプロパティを取得するには、 Item プロパティを使用します。

また、 Find メソッドを使用して、指定した名前のイベントの説明をコレクションから取得できます。

使用例

[Visual Basic, C#, C++] ボタンにかかわるイベントをすべてテキスト ボックスに出力する例を次に示します。この例は、 button1textBox1 がフォーム上でインスタンス化されていることを前提としています。

 
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] JScript のサンプルはありません。Visual Basic、C#、および C++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン 言語のフィルタ をクリックします。

必要条件

名前空間: System.ComponentModel

プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ, .NET Compact Framework - Windows CE .NET

アセンブリ: System (System.dll 内)

参照

EventDescriptorCollection メンバ | System.ComponentModel 名前空間 | EventDescriptor | TypeDescriptor