共用方式為


EventDescriptorCollection.Item[] 屬性

定義

獲得指定的事件。

多載

名稱 Description
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 ,就是要取得或設定的。

屬性值

該 具有 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
來源:
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 型別。 它需要這個, 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屬性值: Synchronization。 這 HostProtectionAttribute 不會影響桌面應用程式(通常透過雙擊圖示、輸入指令或在瀏覽器輸入網址來啟動)。 欲了解更多資訊,請參閱 HostProtectionAttribute 類別或 SQL Server 程式設計與主機保護屬性

另請參閱

適用於