Control.ProcessCmdKey(Message, Keys) 方法

定義

處理命令按鍵。Processes a command key.

protected:
 virtual bool ProcessCmdKey(System::Windows::Forms::Message % msg, System::Windows::Forms::Keys keyData);
protected virtual bool ProcessCmdKey (ref System.Windows.Forms.Message msg, System.Windows.Forms.Keys keyData);
abstract member ProcessCmdKey : Message * System.Windows.Forms.Keys -> bool
override this.ProcessCmdKey : Message * System.Windows.Forms.Keys -> bool
Protected Overridable Function ProcessCmdKey (ByRef msg As Message, keyData As Keys) As Boolean

參數

msg
Message

由參考所傳遞的 Message,代表要處理的視窗訊息。A Message, passed by reference, that represents the window message to process.

keyData
Keys

其中一個 Keys 值,表示要處理的按鍵。One of the Keys values that represents the key to process.

傳回

如果字元已由控制項處理,則為 true,否則為 falsetrue if the character was processed by the control; otherwise, false.

備註

在訊息前置處理期間,會呼叫這個方法來處理命令索引鍵。This method is called during message preprocessing to handle command keys. 命令鍵是一律優先于一般輸入索引鍵的索引鍵。Command keys are keys that always take precedence over regular input keys. 命令索引鍵的範例包括加速器和功能表快捷方式。Examples of command keys include accelerators and menu shortcuts. 方法必須傳回 true,以表示它已處理命令索引鍵,或 false 表示索引鍵不是命令索引鍵。The method must return true to indicate that it has processed the command key, or false to indicate that the key is not a command key. 只有當控制項裝載于 Windows Forms 應用程式或 ActiveX 控制項時,才會呼叫這個方法。This method is only called when the control is hosted in a Windows Forms application or as an ActiveX control.

ProcessCmdKey 方法會先決定控制項是否具有 ContextMenu,如果是,則會啟用 ContextMenu 來處理命令索引鍵。The ProcessCmdKey method first determines whether the control has a ContextMenu, and if so, enables the ContextMenu to process the command key. 如果命令索引鍵不是功能表快捷方式,而且控制項具有父系,則會將索引鍵傳遞給父系的 ProcessCmdKey 方法。If the command key is not a menu shortcut and the control has a parent, the key is passed to the parent's ProcessCmdKey method. 最後的結果是命令按鍵在控制項階層中是「反升」。The net effect is that command keys are "bubbled" up the control hierarchy. 除了使用者按下的按鍵之外,索引鍵資料也會指出與金鑰同步選取的輔助按鍵(如果有的話)。In addition to the key the user pressed, the key data also indicates which, if any, modifier keys were pressed at the same time as the key. 輔助按鍵包括 SHIFT、CTRL 和 ALT 鍵。Modifier keys include the SHIFT, CTRL, and ALT keys.

給繼承者的注意事項

在衍生類別中覆寫 ProcessCmdKey(Message, Keys) 方法時,控制項應傳回 true,表示它已處理過索引鍵。When overriding the ProcessCmdKey(Message, Keys) method in a derived class, a control should return true to indicate that it has processed the key. 對於控制項不會處理的索引鍵,應傳回呼叫基類的 ProcessCmdKey(Message, Keys) 方法的結果。For keys that are not processed by the control, the result of calling the base class's ProcessCmdKey(Message, Keys) method should be returned. 如果您需要覆寫這個方法,則控制項不常發生。Controls will seldom, if ever, need to override this method.

安全性

SecurityPermission
適用于立即呼叫端和繼承類別,以呼叫此方法。for the immediate caller and inheriting classes to call this method. 關聯的列舉型別:UnmanagedCodeAssociated enumeration: UnmanagedCode.

適用於