Control.ProcessMnemonic(Char) Método

Definição

Processa um carácter mnemónico.

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

Parâmetros

charCode
Char

A personagem a processar.

Devoluções

true se o carácter foi processado como um mnemónico pelo controlo; caso contrário, false.

Exemplos

O exemplo de código seguinte demonstra uma extensão da classe button que sobrepõe o ProcessMnemonic método para exibir um comportamento personalizado. O exemplo também demonstra a utilização das CanSelect propriedades e.IsMnemonic Para executar este exemplo, cole o seguinte código após uma classe de formulário, no mesmo ficheiro. Adicione um botão de tipo MnemonicButton ao formulário.

// 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

Observações

Este método chama-se para dar a um controlo a oportunidade de processar um carácter mnemónico. O método deve determinar se o controlo está num estado para processar mnemónicos e se o carácter dado representa um mnemónico. Se sim, o método deve realizar a ação associada ao mnemónico e devolver true. Se não, o método deverá devolver false. As implementações deste método usam-no IsMnemonic frequentemente para determinar se o carácter dado corresponde a um mnemónico no texto do controlo.

Por exemplo:

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

Esta implementação padrão do ProcessMnemonic método simplesmente retorna false para indicar que o controlo não tem mnemónica.

Aplica-se a

Ver também