I saw on the internet the solution was setting the KeyPreview
to true
. I have tried it, and it still didn't work. Why when I press one of the arrows (down, up, left, or right) the label still doesn't show off?
To make this clear: a regular letter does work and makes the label show off. The thing is that the arrows (down, up, left or right) don't work.
I think I know why - the "focus" is on the button and not on the form.
I searched for this on the internet, and I found that I need to make the KeyPreview
set as true
. I did it, and still, it doesn't show the label when I press the arrows, only when I press letters.
If I remove the button, the arrows do work.
Here is my code:
public partial class Form1: Form
{
public Form1()
{
InitializeComponent();
label1.Visible = false;
this.KeyPreview = true;
this.KeyDown += Form1_KeyDown;
}
private void Form1_KeyDown(object sender, KeyEventArgs e)
{
label1.Visible = true;
}
private void button1_Click(object sender, EventArgs e)
{
}
}