Control.ProcessMnemonic 方法

处理助记键字符。

**命名空间:**System.Windows.Forms
**程序集:**System.Windows.Forms(在 system.windows.forms.dll 中)

语法

声明
Protected Friend Overridable Function ProcessMnemonic ( _
    charCode As Char _
) As Boolean
用法
Dim charCode As Char
Dim returnValue As Boolean

returnValue = Me.ProcessMnemonic(charCode)
protected internal virtual bool ProcessMnemonic (
    char charCode
)
protected public:
virtual bool ProcessMnemonic (
    wchar_t charCode
)
protected boolean ProcessMnemonic (
    char charCode
)
protected internal function ProcessMnemonic (
    charCode : char
) : boolean

参数

  • charCode
    要处理的字符。

返回值

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

备注

调用此方法是为了给控件提供处理助记键字符的机会。此方法应确定控件是否处于处理助记键的状态以及给定字符是否表示助记键。如果是,此方法应执行与助记键关联的操作并返回 true。如果不是,此方法应返回 false。此方法的实现常常使用 IsMnemonic 方法来确定给定字符是否与控件的文本中的助记键匹配。

例如:

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

ProcessMnemonic 方法的这种默认实现只是返回 false 以指示控件没有助记键。

示例

下面的代码示例阐释了该按钮类的一个扩展,该扩展重写 ProcessMnemonic 方法以显示自定义行为。该示例还阐释了如何使用 CanSelectIsMnemonic 属性。要运行该示例,请将以下代码粘贴到同一文件中的窗体类后面。将一个 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;
   }

};

.NET Framework 安全性

平台

Windows 98、Windows 2000 SP4、Windows CE、Windows Millennium Edition、Windows Mobile for Pocket PC、Windows Mobile for Smartphone、Windows Server 2003、Windows XP Media Center Edition、Windows XP Professional x64 Edition、Windows XP SP2、Windows XP Starter Edition

.NET Framework 并不是对每个平台的所有版本都提供支持。有关受支持版本的列表,请参见系统要求

版本信息

.NET Framework

受以下版本支持:2.0、1.1、1.0

请参见

参考

Control 类
Control 成员
System.Windows.Forms 命名空间
IsMnemonic
ProcessDialogChar