Control.IsMnemonic 方法

搜索指定的字符串,以确定指定字符是否是分配给此控件的助记键字符。

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

语法

声明
Public Shared Function IsMnemonic ( _
    charCode As Char, _
    text As String _
) As Boolean
用法
Dim charCode As Char
Dim text As String
Dim returnValue As Boolean

returnValue = Control.IsMnemonic(charCode, text)
public static bool IsMnemonic (
    char charCode,
    string text
)
public:
static bool IsMnemonic (
    wchar_t charCode, 
    String^ text
)
public static boolean IsMnemonic (
    char charCode, 
    String text
)
public static function IsMnemonic (
    charCode : char, 
    text : String
) : boolean

参数

  • charCode
    要测试的字符。
  • text
    要搜索的字符串。

返回值

如果 charCode 字符是分配给控件的助记键字符,则为 true;否则为 false

备注

助记键字符是紧随在 String 中第一个“&”实例后面的字符。

示例

下面的代码示例阐释了该按钮类的一个扩展,该扩展重写 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 命名空间
ProcessMnemonic