Control.IsMnemonic(Char, String) 메서드

정의

지정된 문자가 특정 문자열의 컨트롤에 할당된 니모닉 문자인지를 확인합니다.

public:
 static bool IsMnemonic(char charCode, System::String ^ text);
public static bool IsMnemonic (char charCode, string text);
public static bool IsMnemonic (char charCode, string? text);
static member IsMnemonic : char * string -> bool
Public Shared Function IsMnemonic (charCode As Char, text As String) As Boolean

매개 변수

charCode
Char

테스트할 문자입니다.

text
String

검색할 문자열입니다.

반환

charCode 문자가 컨트롤에 할당된 니모닉 문자이면 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

설명

니모닉 문자는 에서 "&"의 첫 번째 instance 바로 뒤에 있는 문자입니다String.

적용 대상

추가 정보