Control.ProcessMnemonic メソッド

ニーモニック文字を処理します。

Protected Overridable Function ProcessMnemonic( _
   ByVal charCode As Char _) As Boolean
[C#]
protected virtual bool ProcessMnemonic(charcharCode);
[C++]
protected: virtual bool ProcessMnemonic(__wchar_tcharCode);
[JScript]
protected function ProcessMnemonic(
   charCode : Char) : Boolean;

パラメータ

  • charCode
    処理対象の文字。

戻り値

文字がコントロールによってニーモニックとして処理された場合は true 。それ以外の場合は false

解説

このメソッドは、ニーモニック文字を処理する機会をコントロールに与えるために呼び出されます。このメソッドは、コントロールがニーモニックを処理する状態にあるかどうか、また、与えられた文字がニーモニックを表しているかどうかを判断します。この場合、このメソッドはニーモニックに関連付けられたアクションを実行し、 true を返します。それ以外の場合、メソッドは false を返します。このメソッドの実装では、多くの場合において IsMnemonic メソッドを使用して、指定された文字がコントロールのテキスト内のニーモニックと一致するかどうかを判断します。

その例を次に示します。

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

ProcessMnemonic メソッドのこの既定の実装では、コントロールにニーモニックがないことを示すために、単に false を返します。

使用例

[Visual Basic, C#] 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.  
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.
    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

[C#] 
// 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;
    }

}

[C++, JScript] C++ および JScript のサンプルはありません。Visual Basic および C# のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン 言語のフィルタ をクリックします。

必要条件

プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ

.NET Framework セキュリティ:

参照

Control クラス | Control メンバ | System.Windows.Forms 名前空間 | IsMnemonic | ProcessDialogChar