MenuItem.OnSelect(EventArgs) Método

Definición

Genera el evento Select.Raises the Select event.

protected:
 virtual void OnSelect(EventArgs ^ e);
protected virtual void OnSelect (EventArgs e);
abstract member OnSelect : EventArgs -> unit
override this.OnSelect : EventArgs -> unit
Protected Overridable Sub OnSelect (e As EventArgs)

Parámetros

e
EventArgs

Objeto EventArgs que contiene los datos del evento.An EventArgs that contains the event data.

Ejemplos

En el ejemplo de código siguiente se muestra cómo Select utilizar el evento MenuItem de la clase para asignar texto de StatusBarPanel ayuda a StatusBar un de un control.The following code example demonstrates how to use the Select event of the MenuItem class to assign help text to a StatusBarPanel of a StatusBar control. Este ejemplo requiere que MenuItem los objetos menuOpendenominados, menuExit menuSavey se agreguen MainMenu a un control en un formulario.This example requires that MenuItem objects named menuOpen, menuSave, and menuExit are added to a MainMenu control on a form. El ejemplo también requiere que se StatusBar haya agregado al statusBar1 formulario un control denominado.The example also requires that a StatusBar control, named statusBar1 has been added to the form. El StatusBar control debe contener un StatusBarPanel.The StatusBar control should contain a StatusBarPanel.

private:
   void MenuSelected( Object^ sender, System::EventArgs^ /*e*/ )
   {
      if ( sender == menuOpen )
            statusBar1->Panels[ 0 ]->Text = "Opens a file to edit";
      else
      if ( sender == menuSave )
            statusBar1->Panels[ 0 ]->Text = "Saves the current file";
      else
      if ( sender == menuExit )
            statusBar1->Panels[ 0 ]->Text = "Exits the application";
      else
            statusBar1->Panels[ 0 ]->Text = "Ready";
   }
private void MenuSelected(object sender, System.EventArgs e)
{
   if (sender == menuOpen)
      statusBar1.Panels[0].Text = "Opens a file to edit";
   else if(sender == menuSave)
      statusBar1.Panels[0].Text = "Saves the current file";
   else if(sender == menuExit)
      statusBar1.Panels[0].Text = "Exits the application";
   else
      statusBar1.Panels[0].Text = "Ready";
}
Private Sub MenuSelected(ByVal sender As Object, ByVal e As System.EventArgs) _
                     Handles menuOpen.Select, menuExit.Select, menuSave.Select
   If sender Is menuOpen Then
      StatusBar1.Panels(0).Text = "Opens a file to edit"
   Else
      If sender Is menuSave Then
         StatusBar1.Panels(0).Text = "Saves the current file"
      Else
         If sender Is menuExit Then
            StatusBar1.Panels(0).Text = "Exits the application"
         Else
            StatusBar1.Panels(0).Text = "Ready"
         End If
      End If
   End If
End Sub

Comentarios

Cuando se genera un evento, se invoca el controlador de eventos a través de un delegado.Raising an event invokes the event handler through a delegate. Para obtener más información, consulte controlar y provocar eventos.For more information, see Handling and Raising Events.

Notas a los desarrolladores de herederos

Al reemplazar OnSelect(EventArgs) en una clase derivada, asegúrese de llamar al método de OnSelect(EventArgs) la clase base.When overriding OnSelect(EventArgs) in a derived class, be sure to call the base class's OnSelect(EventArgs) method.

Se aplica a