ToolStripDropDown.ProcessMnemonic(Char) Método

Definición

Procesa un carácter de tecla de acceso.

protected public:
 override bool ProcessMnemonic(char charCode);
protected internal override bool ProcessMnemonic (char charCode);
override this.ProcessMnemonic : char -> bool
Protected Friend Overrides Function ProcessMnemonic (charCode As Char) As Boolean

Parámetros

charCode
Char

Carácter que se va a procesar.

Devoluciones

Boolean

true si el control procesó el carácter como carácter de tecla de acceso; de lo contrario, false.

Ejemplos

En el ejemplo de código siguiente se muestra una extensión de la clase de botón que invalida el ProcessMnemonic método para mostrar un comportamiento personalizado. En el ejemplo también se muestra el uso de las CanSelect propiedades y IsMnemonic . Para ejecutar este ejemplo, pegue el código siguiente después de una clase de formulario, en el mismo archivo. Agregue un botón de tipo MnemonicButton al formulario.

// This button is a simple extension of the button class that overrides
// the ProcessMnemonic method.  If the mnemonic is correctly entered,  
// the message box will appear and the click event will be raised.  
// This method makes sure the control is selectable and the 
// mnemonic is correct before displaying the message box
// and triggering the click event.
public ref class MyMnemonicButton: public Button
{
protected:
   bool ProcessMnemonic( char inputChar )
   {
      if ( CanSelect && IsMnemonic( inputChar, this->Text ) )
      {
         MessageBox::Show( "You've raised the click event "
         "using the mnemonic." );
         this->PerformClick();
         return true;
      }

      return false;
   }

};
// This button is a simple extension of the button class that overrides
// the ProcessMnemonic method.  If the mnemonic is correctly entered,  
// the message box will appear and the click event will be raised.  
public class MyMnemonicButton : Button
{
    // This method makes sure the control is selectable and the 
    // mneumonic is correct before displaying the message box
    // and triggering the click event.
    protected override bool ProcessMnemonic(char inputChar)
    {
        if (CanSelect && IsMnemonic(inputChar, this.Text))
        {
            MessageBox.Show("You've raised the click event " +
                "using the mnemonic.");
            this.PerformClick();
            return true;
        }
        return false;
    }
}
' This button is a simple extension of the button class that overrides
' the ProcessMnemonic method.  If the mnemonic is correctly entered,  
' the message box will appear and the click event will be raised.  
Public Class MyMnemonicButton
    Inherits Button

    ' This method makes sure the control is selectable and the 
    ' mneumonic is correct before displaying the message box
    ' and triggering the click event.
    <System.Security.Permissions.UIPermission( _
    System.Security.Permissions.SecurityAction.Demand, Window:=UIPermissionWindow.AllWindows)> _
    Protected Overrides Function ProcessMnemonic( _
        ByVal inputChar As Char) As Boolean

        If (CanSelect And IsMnemonic(inputChar, Me.Text)) Then
            MessageBox.Show("You've raised the click event " _
                & "using the mnemonic.")
            Me.PerformClick()
            Return True
        End If
        Return False
    End Function

End Class

Comentarios

Se llama a este método para dar a un control la oportunidad de procesar un carácter mnemónico. El método debe determinar si el control está en un estado para procesar mnemonics y si el carácter especificado representa una mnemónica. Si es así, el método debe realizar la acción asociada al mnemonic y devolver true. Si no es así, el método debe devolver false. Las implementaciones de este método suelen usar el IsMnemonic método para determinar si el carácter dado coincide con un mnemonic en el texto del control.

Por ejemplo:

if (CanSelect && IsMnemonic(charCode, MyControl.Text) {  
      // Perform action associated with mnemonic.  
       }  

Esta implementación predeterminada del ProcessMnemonic método simplemente devuelve false para indicar que el control no tiene ningún mnemonic.

Se aplica a

Consulte también