Control.ProcessCmdKey(Message, Keys) Control.ProcessCmdKey(Message, Keys) Control.ProcessCmdKey(Message, Keys) Control.ProcessCmdKey(Message, Keys) Method


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

 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 :  * System.Windows.Forms.Keys -> bool
override this.ProcessCmdKey :  * System.Windows.Forms.Keys -> bool
Protected Overridable Function ProcessCmdKey (ByRef msg As Message, keyData As Keys) As Boolean


Message Message Message Message

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

Keys Keys Keys 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表示索引鍵不 command 機碼。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. 如果 command 機碼不是功能表快顯控制項具有父代,要將金鑰傳遞至父系的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.


立即呼叫端和繼承類別呼叫這個方法。for the immediate caller and inheriting classes to call this method. 相關聯的列舉型別: UnmanagedCodeAssociated enumeration: UnmanagedCode.