You can override ProcessCmdKey
and handle your hotkeys there, either in a control or a form.
From MSDN:
The ProcessCmdKey method first
determines whether the control has a
ContextMenu, and if so, enables the
ContextMenu to process the command
key. 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. Modifier keys include the
SHIFT, CTRL, and ALT keys.
For example:
protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
{
// if it is a hotkey, return true; otherwise, return false
switch (keyData)
{
case Keys.Control | Keys.C:
// do something
return true;
default:
break;
}
return base.ProcessCmdKey(ref msg, keyData);
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…