EventDescriptorCollection.Item[] 屬性

定義

取得指定的事件。

多載

Item[Int32]

取得或設定具有指定索引編號的事件。

Item[String]

取得或設定具有指定名稱的事件。

Item[Int32]

來源:
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 的以零起始的索引。

屬性值

具有指定索引編號的 EventDescriptor

例外狀況

index 不是 Item[Int32] 的有效索引。

範例

下列程式代碼範例會 Item[] 使用 屬性,在文字框中列印索引編號所指定的 名稱 EventDescriptor 。 因為索引編號是以零起始,所以本範例會列印第二個 EventDescriptor的名稱。 它要求 button1 已在表單上具現化 和 textBox1

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

備註

索引編號是以零起始。 因此,您必須從特定 EventDescriptor 的數值位置減去 1,才能存取該 EventDescriptor。 例如,若要取得第三 EventDescriptor個 ,您需要指定 myColl[2]

另請參閱

適用於

Item[String]

來源:
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 的名稱。

屬性值

具有指定名稱的 EventDescriptornull (如果事件不存在)。

範例

下列程式代碼範例會 Item[] 使用 屬性來列印索引所指定 之的元件 EventDescriptor 類型。 它要求 button1 已在表單上具現化 和 textBox1

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」 會被視為兩個不同的事件。

注意

HostProtectionAttribute套用至這個類別的屬性具有下列Resources屬性值:SynchronizationHostProtectionAttribute 不會影響桌面應用程式 (這些應用程式的啟動方式一般都是按兩下圖示、輸入命令或在瀏覽器輸入 URL)。 如需詳細資訊,請參閱 類別HostProtectionAttributeSQL Server 程式設計和主機保護屬性

另請參閱

適用於