I have a small form with 9 Check Boxes in it. I am trying to make hotkeys for those boxes that correspond with the Numpad, but I'm having the darnedest time. I have two main problems:
1.
private void checkBox1_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.NumPad7)
{
MessageBox.Show("It's working");
}
}
That is my code. It works, but doesn't do what I want. It makes a message appear, but ONLY if that checkbox is highlighted. I think KeyPreview might help in this context, but the MSDN database didn't help me solve my problem with trying to figure out how to make KeyPreview work.
Second, I want the code to check the box when I hit the hotkey. No combination I can figure using CheckState seems to work. If anyone has some incite, I would greatly appreciate it.
Code from Comments:
public Form2()
{
InitializeComponent();
this.KeyPreview = true;
this.KeyDown += new KeyEventHandler(Form2_KeyDown);
}
private void Form2_KeyDown(object sender, KeyEventArgs e)
{
switch (e.KeyCode)
{
case Keys.NumPad7:
MessageBox.Show("ABC");
break;
default:
break;
}
}