CheckBox.ProcessMnemonic(Char) メソッド

定義

ニーモニック文字を処理します。Processes a mnemonic character.

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

パラメーター

charCode
Char

処理対象の文字。The character to process.

戻り値

文字がコントロールによってニーモニックとして処理された場合は true。それ以外の場合は falsetrue if the character was processed as a mnemonic by the control; otherwise, false.

次のコード例は、カスタム動作を示すためにProcessMnemonicメソッドをオーバーライドする button クラスの拡張を示しています。The following code example demonstrates an extension of the button class that overrides the ProcessMnemonic method to exhibit custom behavior. この例では、プロパティCanSelectIsMnemonicプロパティの使用方法も示しています。The example also demonstrates the use of the CanSelect and IsMnemonic properties. この例を実行するには、同じファイル内のフォームクラスの後に次のコードを貼り付けます。To run this example, paste the following code after a form class, in the same file. MnemonicButtonのボタンをフォームに追加します。Add a button of type MnemonicButton to the form.

// 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.
{
    [UIPermission(
        SecurityAction.Demand, Window = UIPermissionWindow.AllWindows)]
        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

注釈

このメソッドは、ニーモニック文字を処理する機会をコントロールに与えるために呼び出されます。This method is called to give a control the opportunity to process a mnemonic character. メソッドは、コントロールがニーモニックを処理する状態であるかどうか、および指定された文字がニーモニックを表すかどうかを判断する必要があります。The method should determine whether the control is in a state to process mnemonics and if whether the given character represents a mnemonic. その場合、メソッドはニーモニックに関連付けられたアクションを実行trueし、を返します。If so, the method should perform the action associated with the mnemonic and return true. それ以外の場合、メソッドはfalseを返します。If not, the method should return false. このメソッドの実装では、 IsMnemonic多くの場合、メソッドを使用して、指定された文字がコントロールのテキスト内のニーモニックと一致するかどうかを判断します。Implementations of this method often use the IsMnemonic method to determine whether the given character matches a mnemonic in the control's text.

次に例を示します。For example:

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

このProcessMnemonicメソッドの既定の実装は、 falseコントロールにニーモニックがないことを示すために単にを返します。This default implementation of the ProcessMnemonic method simply returns false to indicate that the control has no mnemonic.

適用対象