ContextMenu.ProcessCmdKey(Message, Keys, Control) 方法

定义

处理命令键。Processes a command key.

protected public:
 virtual bool ProcessCmdKey(System::Windows::Forms::Message % msg, System::Windows::Forms::Keys keyData, System::Windows::Forms::Control ^ control);
protected internal virtual bool ProcessCmdKey (ref System.Windows.Forms.Message msg, System.Windows.Forms.Keys keyData, System.Windows.Forms.Control control);
override this.ProcessCmdKey : Message * System.Windows.Forms.Keys * System.Windows.Forms.Control -> bool

参数

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.

control
Control

命令键应用到的控件。The control to which the command key applies.

返回

如果字符已由控件处理,则为 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.

@No__t-0 方法首先确定控件是否有 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.

继承者说明

在派生类中重写 @no__t 0 方法时,控件应返回 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. 对于不是由控件处理的键,应返回调用基类的 @no__t 的结果。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 to call unmanaged code. 关联的枚举: UnmanagedCodeAssociated enumeration: UnmanagedCode

适用于