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

Asked

Viewed 152 times

1

Good evening or good morning depending on where you live I was wondering if any of you could tell me how to open a new form when pressed at the same time alt + F4

  • 1

    PQ you want to use Alt+F4 to open a new form, surely 99.9% of applications use Alt+F4 to close the form.

  • I’m doing alt F4 and that’s what I’m going to use to move to the next level no one will suspect

  • @Pekira, it has not yet become clear the meaning of using this feature, as Pablo Vargas said himself, this feature is used to close the form. Can explain better what the purpose of this resource ?

1 answer

0


To open a new form by clicking alt+F4:

Form 1:

  1. Set the property KeyPreview as true;

       this.KeyPreview = true;
    
  2. Sign the Keydown Event;

       this.KeyDown += Form1_KeyDown;
    
  3. 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 property e.Handled = true; to prevent Form 2 close.

Browser other questions tagged

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