Hide form by pressing key

Asked

Viewed 106 times

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 stay hidden and press F1 again it comes back to.

I tried this, but to no avail:

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

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

       }
   }
  • 1

    give a look at this link, it might help https://social.msdn.microsoft.com/Forums/pt-BR/8d299b9e-bea2-4daf-8705-1394e3e91ca1/maximizingminimizando-e-dragndo-o-form?forum=vscsharppt

  • vlw Itor, helped me enough I gave up the telcas scheme does not work in my form I used a buttom to minimize even.

  • @Cerraossouc The answer solved your question? Do you think you can accept it? See [tour] if you don’t know how to do it. This would help a lot to indicate that the solution was useful for you. You can also vote on any question or answer you find useful on the entire site (when you have 15 points).

1 answer

2

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

private void Form1_KeyDown(object sender, KeyEventArgs e) => if (e.KeyCode == Keys.F1) this.Hide();

I put in the Github for future reference.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.