Multiple hot key selection

G

Guest

I have a ContextMenu that begs to have hot keys. I tried adding some but am
having issues understanding how to properly manage the events when dealing
with more than one key pressed (e.g., Alt-F1, Cntr-C) or even with F2. Can
someone point me to some documentation that explains how to properly handle
these type of keyboard inputs in ContextMenus?
 
R

Rachel Suddeth

If you are using the MenuItem controls, there is a "shortcut" property that
will take just about anything and trigger selection of that menu item. If
you set it through VS Properties box, you can just select from a list.
Otherwise, there is an enum called "Shortcut" that you can use for this (in
System.Windows.Forms, I think.)

If you want to handle everything manually, you'd probably need to use the
ProcessCmdKey(). Code inside would look something like this:

switch (keyData)
{
case Keys.F3:
HandleF3Press();
return true;
case Keys.Control | Keys.Up
HandleCtrlUpArrow();
return true;
case Keys.Alt | Keys.D1:
HandleAltOne();
return true;
default:
return base.ProcessCmdKey(ref msg, keyData);
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top