When the main form loads, I am trying to set up a key event handler as follows:
private void FormMain_Load(object sender, EventArgs e)
{
KeyDown += FormMain_KeyDown;
}
and the function that is called:
private void FormMain_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Escape)
{
// Do something.
}
}
The problem is that the form doesn't react to Escape (or any other key I tried). And the funny thing is that a different form from the same project uses similar code without any issues. Can anyone please tell me what I am doing wrong?