CheckBox.ProcessMnemonic(Char) 方法

定义

处理助记键字符。

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

参数

charCode
Char

要处理的字符。

返回

Boolean

如果字符由控件作为助记键处理,则为 true;否则为 false

示例

下面的代码示例演示了一个按钮类的扩展,该扩展重写 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

注解

调用此方法可让控件有机会处理助记字符。 该方法应确定控件是否处于处理助记状态,以及给定字符是否表示助记。 如果是这样,该方法应执行与助记和返回 true关联的操作。 否则,该方法应返回 false。 此方法的实现通常使用 IsMnemonic 该方法来确定给定字符是否与控件文本中的助记符匹配。

例如:

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

此方法的默认实现 ProcessMnemonic 仅返回 false 以指示控件没有助记。

适用于