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 : 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 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.

方法首先确定控件是否ContextMenu具有, ContextMenu如果是,则使能够处理命令键。 ProcessCmdKeyThe 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.

适用于