Pages

c# Sharp How can I disable the ALT+F4 method of closing the application

frist way

private void Form1_FormClosing(object sender, FormClosingEventArgs e) 
{ 
    e.
Cancel = true; 
} 

second way
You can handle "Alt+F4" KeyDown to disable it.

1. set "KeyPreview" of your form to "true"

2. add "KeyDown" handler for your form (or override "OnKeyDown" method)

private void Form1_KeyDown(object sender
, System.Windows.Forms.KeyEventArgs e) {
if( e.Alt && e.KeyCode==Keys.F4 ) {
e.Handled=true;
}
}

0 comment:

إرسال تعليق

Link With in

Related Posts Plugin for WordPress, Blogger...