Hide form when pressing key

0

I created a form, I do not want to use minimize or maximize button, I want to use for example when pressing "F1" my form is hidden and press F1 again it reappears.

I tried this, but without success:

       private void Form1_KeyDown(object sender, KeyEventArgs e)
   {
       if (e.KeyCode == Keys.F1)
       {

            Form1 fm = new Form1();
            fm .Hide();

       }
   }
    
asked by anonymous 15.11.2016 / 03:00

1 answer

2

You are creating a form name and hiding it, you can not, you have to hide the current one:

private void Form1_KeyDown(object sender, KeyEventArgs e) {
    if (e.KeyCode == Keys.F1) {
        this.Hide();
    }
}
    
15.11.2016 / 03:05