Control.ProcessMnemonic(Char) Метод

Определение

Обрабатывает назначенный символ.

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

Параметры

charCode
Char

Символ, подлежащий обработке.

Возвращаемое значение

Boolean

Значение true, если символ был обработан элементом управления как назначенный; в противном случае — значение false.

Примеры

В следующем примере кода демонстрируется расширение класса button, которое переопределяет ProcessMnemonic метод для демонстрации пользовательского поведения. В примере также демонстрируется использование CanSelect свойств и IsMnemonic свойств. Чтобы запустить этот пример, вставьте следующий код после класса формы в том же файле. Добавьте в форму кнопку типа MnemonicButton .

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

Комментарии

Этот метод вызывается для предоставления элементу управления возможность обработки символа mnemonic. Метод должен определить, находится ли элемент управления в состоянии для обработки mnemonics и представляет ли заданный символ mnemonic. В этом случае метод должен выполнить действие, связанное с mnemonic и возвращаемым true. В противном случае метод должен возвращать false. Реализации этого метода часто используют IsMnemonic этот метод, чтобы определить, совпадает ли заданный символ с mnemonic в тексте элемента управления.

Пример:

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

Эта реализация ProcessMnemonic метода по умолчанию просто возвращается false , чтобы указать, что элемент управления не имеет mnemonic.

Применяется к

См. также раздел