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

処理する文字。

返品

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を返すだけです。

適用対象

こちらもご覧ください