次の方法で共有


EventDescriptorCollection.Item[] プロパティ

定義

指定したイベントを取得します。

オーバーロード

名前 説明
Item[Int32]

指定したインデックス番号を持つイベントを取得または設定します。

Item[String]

指定した名前のイベントを取得または設定します。

Item[Int32]

ソース:
EventDescriptorCollection.cs
ソース:
EventDescriptorCollection.cs
ソース:
EventDescriptorCollection.cs
ソース:
EventDescriptorCollection.cs
ソース:
EventDescriptorCollection.cs

指定したインデックス番号を持つイベントを取得または設定します。

public:
 virtual property System::ComponentModel::EventDescriptor ^ default[int] { System::ComponentModel::EventDescriptor ^ get(int index); };
public virtual System.ComponentModel.EventDescriptor? this[int index] { get; }
public virtual System.ComponentModel.EventDescriptor this[int index] { get; }
member this.Item(int) : System.ComponentModel.EventDescriptor
Default Public Overridable ReadOnly Property Item(index As Integer) As EventDescriptor

パラメーター

index
Int32

取得または設定する EventDescriptor の 0 から始まるインデックス番号。

プロパティ値

指定したインデックス番号を持つ EventDescriptor

例外

index は、 Item[Int32]の有効なインデックスではありません。

次のコード例では、 Item[] プロパティを使用して、インデックス番号で指定された EventDescriptor の名前をテキスト ボックスに出力します。 インデックス番号は 0 から始まるため、この例では 2 番目の EventDescriptorの名前を出力します。 フォームで button1textBox1 がインスタンス化されている必要があります。

private:
   void PrintIndexItem()
   {
      
      // Creates a new collection and assigns it the events for button1.
      EventDescriptorCollection^ events = TypeDescriptor::GetEvents( button1 );
      
      // Prints the second event's name.
      textBox1->Text = events[ 1 ]->ToString();
   }
private void PrintIndexItem() {
    // Creates a new collection and assigns it the events for button1.
    EventDescriptorCollection events = TypeDescriptor.GetEvents(button1);
 
    // Prints the second event's name.
    textBox1.Text = events[1].ToString();
 }
Private Sub PrintIndexItem()
    ' Creates a new collection and assigns it the events for button1.
    Dim events As EventDescriptorCollection = TypeDescriptor.GetEvents(button1)
    
    ' Prints the second event's name.
    textBox1.Text = events(1).ToString()
End Sub

注釈

インデックス番号は 0 から始まります。 したがって、そのEventDescriptorにアクセスするには、特定のEventDescriptorの数値位置から 1 を減算する必要があります。 たとえば、3 番目の EventDescriptorを取得するには、 myColl[2]を指定する必要があります。

こちらもご覧ください

適用対象

Item[String]

ソース:
EventDescriptorCollection.cs
ソース:
EventDescriptorCollection.cs
ソース:
EventDescriptorCollection.cs
ソース:
EventDescriptorCollection.cs
ソース:
EventDescriptorCollection.cs

指定した名前のイベントを取得または設定します。

public:
 virtual property System::ComponentModel::EventDescriptor ^ default[System::String ^] { System::ComponentModel::EventDescriptor ^ get(System::String ^ name); };
public virtual System.ComponentModel.EventDescriptor this[string name] { get; }
member this.Item(string) : System.ComponentModel.EventDescriptor
Default Public Overridable ReadOnly Property Item(name As String) As EventDescriptor

パラメーター

name
String

取得または設定する EventDescriptor の名前。

プロパティ値

指定した名前の EventDescriptor 。イベントが存在しない場合は null

次のコード例では、 Item[] プロパティを使用して、インデックスで指定された EventDescriptor のコンポーネントの型を出力します。 フォームで button1textBox1 がインスタンス化されている必要があります。

private:
   void PrintIndexItem2()
   {
      
      // Creates a new collection and assigns it the events for button1.
      EventDescriptorCollection^ events = TypeDescriptor::GetEvents( button1 );
      
      // Sets an EventDescriptor to the specific event.
      EventDescriptor^ myEvent = events[ "KeyDown" ];
      
      // Prints the name of the event.
      textBox1->Text = myEvent->Name;
   }
private void PrintIndexItem2() {
    // Creates a new collection and assigns it the events for button1.
    EventDescriptorCollection events = TypeDescriptor.GetEvents(button1);
 
    // Sets an EventDescriptor to the specific event.
    EventDescriptor myEvent = events["KeyDown"];
 
    // Prints the name of the event.
    textBox1.Text = myEvent.Name;
 }
Private Sub PrintIndexItem2()
    ' Creates a new collection and assigns it the events for button1.
    Dim events As EventDescriptorCollection = TypeDescriptor.GetEvents(button1)
    
    ' Sets an EventDescriptor to the specific event.
    Dim myEvent As EventDescriptor = events("KeyDown")
    
    ' Prints the name of the event.
    textBox1.Text = myEvent.Name
End Sub

注釈

Item[] プロパティは、名前を検索するときに大文字と小文字が区別されます。 つまり、名前 "Ename" と "ename" は 2 つの異なるイベントと見なされます。

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

こちらもご覧ください

適用対象