c # when pressed at the same time alt + f4 opens a new form

1

Good night or good day depending on where you live I wanted to know if any of you could tell how I can open a new form when pressed at the same time alt + f4

    
asked by anonymous 25.07.2016 / 22:22

1 answer

0

To open a new form by clicking alt+F4 :

Form 1:

  • Set the property KeyPreview to true ;

       this.KeyPreview = true;
    
  • Sign the KeyDown event;

       this.KeyDown += Form1_KeyDown;
    
  • Complete;

    public Form1()
    {
       InitializeComponent();
       this.KeyPreview = true;
       this.KeyDown += Form1_KeyDown;
    }
    private void Form1_KeyDown(object sender, KeyEventArgs e)
    {
        if(e.Alt&&e.KeyCode==Keys.F4)
        {
           Form2 form2 = new Form2();
           form2.Show();
           e.Handled = true;
        }
    }
    
  • Important

      

    Set the e.Handled = true; property to prevent Form 2   close.

        
    26.07.2016 / 01:47