tags:

views:

55

answers:

1

How can I ignore Alt+F4 in WPF Application?

+4  A: 

You can impement OnClosing event on TForm and set cea.Cancel = true; when cea is CancelEventArgs from OnClosing argument.

http://msdn.microsoft.com/en-us/library/system.windows.forms.form.onclosing.aspx

C#

private void Form1_Closing(Object sender, CancelEventArgs e) {
   e.Cancel = true;
}

C++

void Form1_Cancel( Object^ /*sender*/, CancelEventArgs^ e )
{
   e->Cancel = true;
}

VB.NET

Private Sub Form1_Closing(sender As Object, e As _
   System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
    e.Cancel = True
End Sub 'Form1_Closing
Svisstack
Would this also prevent closing the app via the standard Windows White X at the top right?
Nate Bross
@Nate Bross: Yes.
Svisstack
If you want to limit the ways your end user can close an application, you'll specifically have to capture the event that is allowed to close the window, set some flag to say the app is now allowed to close, and then in Form_Closing, allow it to continue if your flag is set.
Daniel Joseph