Partilhar via


EventDescriptorCollection.Item[] Propriedade

Definição

Obtém o evento especificado.

Sobrecargas

Nome Description
Item[Int32]

Obtém ou define o evento com o número de índice especificado.

Item[String]

Obtém ou define o evento com o nome especificado.

Item[Int32]

Origem:
EventDescriptorCollection.cs
Origem:
EventDescriptorCollection.cs
Origem:
EventDescriptorCollection.cs
Origem:
EventDescriptorCollection.cs
Origem:
EventDescriptorCollection.cs

Obtém ou define o evento com o número de índice especificado.

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

Parâmetros

index
Int32

O número de índice baseado em zero do EventDescriptor a ser obtido ou definido.

Valor da propriedade

Com EventDescriptor o número de índice especificado.

Exceções

index não é um índice válido para Item[Int32].

Exemplos

O exemplo de código a seguir usa a Item[] propriedade para imprimir o nome do EventDescriptor especificado pelo número de índice em uma caixa de texto. Como o número de índice é baseado em zero, este exemplo imprime o nome do segundo EventDescriptor. Ele requer isso button1 e textBox1 foi instanciado em um formulário.

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

Comentários

O número do índice é baseado em zero. Portanto, você deve subtrair 1 da posição numérica de um determinado EventDescriptor para acessá-lo EventDescriptor. Por exemplo, para obter o terceiro EventDescriptor, você precisa especificar myColl[2].

Confira também

Aplica-se a

Item[String]

Origem:
EventDescriptorCollection.cs
Origem:
EventDescriptorCollection.cs
Origem:
EventDescriptorCollection.cs
Origem:
EventDescriptorCollection.cs
Origem:
EventDescriptorCollection.cs

Obtém ou define o evento com o nome especificado.

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

Parâmetros

name
String

O nome do EventDescriptor a ser obtido ou definido.

Valor da propriedade

Com EventDescriptor o nome especificado ou null se o evento não existir.

Exemplos

O exemplo de código a seguir usa a Item[] propriedade para imprimir o tipo do componente para o EventDescriptor especificado pelo índice. Ele requer isso button1 e textBox1 foi instanciado em um formulário.

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

Comentários

A Item[] propriedade diferencia maiúsculas de minúsculas ao pesquisar nomes. Ou seja, os nomes "Ename" e "ename" são considerados dois eventos diferentes.

Observação

O HostProtectionAttribute atributo aplicado a essa classe tem o seguinte Resources valor de propriedade: Synchronization. Isso HostProtectionAttribute não afeta aplicativos da área de trabalho (que normalmente são iniciados clicando duas vezes em um ícone, digitando um comando ou inserindo uma URL em um navegador). Para obter mais informações, consulte a HostProtectionAttribute classe ou os atributos de programação e proteção de host do SQL Server.

Confira também

Aplica-se a