Control.ProcessMnemonic(Char) 方法
定義
處理助憶鍵字元。Processes a mnemonic character.
protected public:
virtual bool ProcessMnemonic(char charCode);
protected:
virtual bool ProcessMnemonic(char charCode);
protected internal virtual bool ProcessMnemonic (char charCode);
protected virtual bool ProcessMnemonic (char charCode);
abstract member ProcessMnemonic : char -> bool
override this.ProcessMnemonic : char -> bool
Protected Friend Overridable Function ProcessMnemonic (charCode As Char) As Boolean
Protected Overridable Function ProcessMnemonic (charCode As Char) As Boolean
參數
- charCode
- Char
要處理的字元。The character to process.
傳回
如果控制項已將字元當成助憶鍵處理,則為 true
,否則為 false
。true
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. 此範例也會示範 CanSelect 和 IsMnemonic 屬性的用法。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.