I want to detect pressed key on my form. Let's say I want to show message when F1
key is pressed.
I added code to KeyUp
event related with Form1
private void Form1_KeyUp(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.F1)
{
MessageBox.Show("Key Pressed ");
}
}
The thing is, that pressing F1 does not do anything. Not at all. Does anybody have any idea why does that not work?
Solution
I had to change Form1 KeyPreview
properties to "true" and delete this.Controls.Add(this.webControl1);
from InitializeComponent()
in Form1.Designer.cs
Does anybody know how to solve my problem without deleting row from InitializeComponent()
?