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

定义

处理命令键。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 :  * 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

参数

msg
Message Message Message Message

通过引用传递的 Message,表示要处理的窗口消息。A Message, passed by reference, that represents the window message to process.

keyData
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以指示密钥不是命令键。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 窗体应用程序或作为 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.

适用于