Control.ProcessKeyMessage(Message) 方法


處理鍵盤訊息。Processes a keyboard message.

protected public:
 virtual bool ProcessKeyMessage(System::Windows::Forms::Message % m);
protected internal virtual bool ProcessKeyMessage (ref System.Windows.Forms.Message m);
abstract member ProcessKeyMessage : Message -> bool
override this.ProcessKeyMessage : Message -> bool
Protected Friend Overridable Function ProcessKeyMessage (ByRef m As Message) As Boolean



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



如果控制項已處理訊息,則為 true,否則為 falsetrue if the message was processed by the control; otherwise, false.


當控制項收到鍵盤訊息時,就會呼叫這個方法。This method is called when a control receives a keyboard message. 方法會先決定控制項是否具有父系;若是如此,它會呼叫父系的 ProcessKeyPreview 方法。The method first determines whether the control has a parent; if so, it calls the parent's ProcessKeyPreview method. 如果父系的 ProcessKeyPreview 方法不會處理訊息,則會呼叫 ProcessKeyEventArgs 方法來產生適當的鍵盤事件。If the parent's ProcessKeyPreview method does not process the message then the ProcessKeyEventArgs method is called to generate the appropriate keyboard events. m 參數包含必須處理的視窗訊息。The m parameter contains the window message that must be processed. Message.Msg 屬性的可能值為 WM_CHAR、WM_KEYDOWN、WM_SYSKEYDOWN、WM_KEYUP 和 WM_SYSKEYUP。Possible values for the Message.Msg property are WM_CHAR, WM_KEYDOWN, WM_SYSKEYDOWN, WM_KEYUP, and WM_SYSKEYUP.


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