ToolStripDropDown.ProcessMnemonic(Char) 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
處理助憶鍵字元。
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
,表示控制項沒有助憶鍵。