Control.ProcessMnemonic(Char) Control.ProcessMnemonic(Char) Control.ProcessMnemonic(Char) Control.ProcessMnemonic(Char) Method

Definição

Processa um caractere mnemônico.Processes a mnemonic character.

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

Parâmetros

charCode
Char Char Char Char

O caractere a ser processado.The character to process.

Retornos

true se o caractere tiver sido processado como mnemônico pelo controle; caso contrário, false.true if the character was processed as a mnemonic by the control; otherwise, false.

Exemplos

O exemplo de código a seguir demonstra uma extensão da classe Button que substitui ProcessMnemonic o método para exibir o comportamento personalizado.The following code example demonstrates an extension of the button class that overrides the ProcessMnemonic method to exhibit custom behavior. O exemplo também demonstra o uso das CanSelect Propriedades e. IsMnemonicThe example also demonstrates the use of the CanSelect and IsMnemonic properties. Para executar este exemplo, Cole o código a seguir após uma classe de formulário, no mesmo arquivo.To run this example paste the following code after a form class, in the same file. Adicione um botão do tipo MnemonicButton ao formulário.Add a button of type MnemonicButton to the form.

// 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.
{
	[UIPermission(
        SecurityAction.Demand, Window = UIPermissionWindow.AllWindows)]
        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.This method is called to give a control the opportunity to process a mnemonic character. 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.The method should determine whether the control is in a state to process mnemonics and if whether the given character represents a mnemonic. Nesse caso, o método deve executar a ação associada ao mnemônico e retornar true.If so, the method should perform the action associated with the mnemonic and return true. Caso contrário, o método deve retornar false.If not, the method should return false. As implementações desse método geralmente usam IsMnemonic o método para determinar se o caractere fornecido corresponde a um mnemônico no texto do controle.Implementations of this method often use the IsMnemonic method to determine whether the given character matches a mnemonic in the control's text.

Por exemplo:For example:

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.This default implementation of the ProcessMnemonic method simply returns false to indicate that the control has no mnemonic.

Segurança

UIPermission
para todas as janelas que herdam classes para chamar esse método.for all windows for inheriting classes to call this method. Enumeração associada: AllWindows valor de UIPermissionWindow.Associated enumeration: AllWindows value of UIPermissionWindow.

Aplica-se a

Veja também