Control.ProcessMnemonic(Char) Control.ProcessMnemonic(Char) Control.ProcessMnemonic(Char) Control.ProcessMnemonic(Char) Method

定義

處理助憶鍵字元。Processes a mnemonic character.

protected:
 virtual bool ProcessMnemonic(char charCode);
protected virtual bool ProcessMnemonic (char charCode);
abstract member ProcessMnemonic : char -> bool
override this.ProcessMnemonic : char -> bool
Protected Overridable Function ProcessMnemonic (charCode As Char) As Boolean

參數

charCode
Char Char Char Char

要處理的字元。The character to process.

傳回

如果控制項已將字元當成助憶鍵處理,則為 true,否則為 falsetrue if the character was processed as a mnemonic by the control; otherwise, false.

範例

下列程式碼範例將示範會覆寫ProcessMnemonic方法以展示自訂行為的按鈕類別的延伸。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.

安全性

UIPermission
適用于繼承類別以呼叫這個方法的所有視窗。for all windows for inheriting classes to call this method. 相關聯的AllWindows列舉: UIPermissionWindow的值。Associated enumeration: AllWindows value of UIPermissionWindow.

適用於

另請參閱