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
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
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.