Grabbing the KeyDown event of a Windows Form is a great way to implement behavior that depends on keyboard input. However, it has this annoying tendecy to "ding" if you use the alt key. Investigating this interesting behavior, I discovered that it occurs before the KeyDown event is raised. Luckily, there is a method that can be overridden to implement the proper code and handle it before it reaches the noisy underbelly of WinForms. The following code snipped illustrates grabbing alt-d. To use it with another key stroke, replace Keys with the ones you want.
protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
{
if (keyData == (keyData | Keys.Alt | Keys.D))
{
//Do Something
return true;
}
return base.ProcessCmdKey(ref msg, keyData);
}
It is important that the base method only be called if your override is not handling the key press.