EventDescriptorCollection.Item[] Propiedad

Definición

Obtiene el evento especificado.

Sobrecargas

Item[Int32]

Obtiene o establece el evento con el número de índice especificado.

Item[String]

Obtiene o establece el evento con el nombre especificado.

Item[Int32]

Source:
EventDescriptorCollection.cs
Source:
EventDescriptorCollection.cs
Source:
EventDescriptorCollection.cs

Obtiene o establece el evento con el 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

Número de índice de base cero del EventDescriptor que se va a obtener o establecer.

Valor de propiedad

EventDescriptor que tiene el número de índice especificado.

Excepciones

index no es un índice válido para Item[Int32].

Ejemplos

En el ejemplo de código siguiente se usa la Item[] propiedad para imprimir el nombre del especificado por el número de EventDescriptor índice en un cuadro de texto. Dado que el número de índice es de base cero, en este ejemplo se imprime el nombre del segundo EventDescriptor. Requiere que button1 y textBox1 se hayan creado instancias en un formulario.

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

Comentarios

El número de índice se basa en cero. Por lo tanto, debe restar 1 de la posición numérica de un determinado EventDescriptor para tener acceso a ese EventDescriptor. Por ejemplo, para obtener el tercer EventDescriptor, debe especificar myColl[2].

Consulte también

Se aplica a

Item[String]

Source:
EventDescriptorCollection.cs
Source:
EventDescriptorCollection.cs
Source:
EventDescriptorCollection.cs

Obtiene o establece el evento con el nombre 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

Nombre del EventDescriptor que se va a obtener o establecer.

Valor de propiedad

EventDescriptor con el nombre especificado, o null si no existe el evento.

Ejemplos

En el ejemplo de código siguiente se usa la Item[] propiedad para imprimir el tipo del componente para el EventDescriptor especificado por el índice. Requiere que button1 y textBox1 se hayan creado instancias en un formulario.

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

Comentarios

La Item[] propiedad distingue mayúsculas de minúsculas al buscar nombres. Es decir, los nombres "Ename" y "ename" se consideran dos eventos diferentes.

Nota

El HostProtectionAttribute atributo aplicado a esta clase tiene el siguiente Resources valor de propiedad: Synchronization. El atributo HostProtectionAttribute no afecta a las aplicaciones de escritorio (que normalmente se inician haciendo doble clic en un icono, escribiendo un comando o introduciendo una dirección URL en el explorador). Para obtener más información, vea la HostProtectionAttribute clase o SQL Server Atributos de programación y protección de host.

Consulte también

Se aplica a