ToolStripDropDown.ProcessMnemonic(Char) メソッド

定義

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

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

パラメーター

charCode
Char

処理対象の文字。

戻り値

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

次のコード例では、 メソッドをオーバーライドしてカスタム動作を示すボタン クラスの ProcessMnemonic 拡張を示します。 この例では、 プロパティと IsMnemonic プロパティのCanSelect使用方法も示します。 この例を実行するには、フォーム クラスの後に次のコードを同じファイルに貼り付けます。 型 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 します。

適用対象

こちらもご覧ください