EventDescriptorCollection.Item[] Propriedade

Definição

Recebe o evento especificado.

Sobrecargas

Name Description
Item[Int32]

Recebe ou define o evento com o número de índice especificado.

Item[String]

Recebe ou define o evento com o nome especificado.

Item[Int32]

Recebe 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; }
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 para obter ou definir.

Valor de Propriedade

O EventDescriptor com o número de índice especificado.

Exceções

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

Exemplos

O seguinte exemplo de código usa a Item[] propriedade para imprimir o nome especificado EventDescriptor pelo número de índice numa caixa de texto. Como o número de índice é baseado em zero, este exemplo imprime o nome do segundo EventDescriptor. Requer isso button1 e textBox1 ter sido instanciado num 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

Observações

O número do índice é baseado em zero. Portanto, deve subtrair 1 da posição numérica de um particular EventDescriptor para aceder a esse EventDescriptor. Por exemplo, para obter o terceiro EventDescriptor, precisa de especificar myColl[2].

Ver também

Aplica-se a

Item[String]

Recebe 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 que se deve obter ou definir.

Valor de Propriedade

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

Exemplos

O exemplo de código seguinte utiliza a Item[] propriedade para imprimir o tipo do componente especificado EventDescriptor pelo índice. Requer isso button1 e textBox1 ter sido instanciado num 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

Observações

A Item[] propriedade é sensível a maiúsculas minúsculas ao procurar nomes. Ou seja, os nomes "Ename" e "ename" são considerados dois eventos diferentes.

Note

O HostProtectionAttribute atributo aplicado a esta classe tem o seguinte Resources valor de propriedade: Synchronization. Isto HostProtectionAttribute não afeta aplicações de ambiente de trabalho (que normalmente são iniciadas com duplo clique num ícone, digitação de um comando ou introdução de um URL no navegador). Para mais informações, consulte a classe HostProtectionAttribute ou SQL Server Atributos de Programação e Proteção de Host.

Ver também

Aplica-se a