In my previous post “How to Tab Through Controls on a Form With Alternative Keys using C#” I talked about one way to move the focus among all the controls on a form.
Here is an alternative way to achieve the same function using SendKeys. This method overrides the ProcessCmdKey function and intercepts the actual “+” key and “-” key strokes and translate them to TAB and SHIFT-TAB using SendKeys method. It is simpler then my previous post because it does not need to determine the current focus. Depends on what you want to achieve, either version should work fine.
protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
{
//plus key
if (keyData == Keys.Add)
{
SendKeys.Send(“{TAB}”);
return true;
} //minus key
else if (keyData == Keys.Subtract)
{
SendKeys.Send(“+{TAB}”);
return true;
}return base.ProcessCmdKey (ref msg, keyData);
}