ToolStripDropDown.ProcessMnemonic(Char) Método

Definição

Processa um caractere mnemônico.

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

O caractere a ser processado.

Retornos

true se o caractere tiver sido processado como mnemônico pelo controle; caso contrário, false.

Exemplos

O exemplo de código a seguir demonstra uma extensão da classe de botão que substitui o ProcessMnemonic método para exibir o comportamento personalizado. O exemplo também demonstra o uso das CanSelect propriedades e IsMnemonic . Para executar este exemplo, cole o código a seguir após uma classe de formulário, no mesmo arquivo. Adicione um botão do 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

Comentários

Esse método é chamado para dar a um controle a oportunidade de processar um caractere mnemônico. O método deve determinar se o controle está em um estado para processar mnemônicos e se o caractere determinado representa um mnemônico. Nesse caso, o método deve executar a ação associada ao mnemônico e retornar true. Caso contrário, o método deve retornar false. As implementações desse método geralmente usam o IsMnemonic método para determinar se o caractere especificado corresponde a um mnemônico no texto do controle.

Por exemplo:

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

Essa implementação padrão do ProcessMnemonic método simplesmente retorna false para indicar que o controle não tem mnemônico.

Aplica-se a

Confira também