Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ignore Alt+F4 in WPF Application

Tags:

c#

wpf

How can I ignore Alt+F4 in WPF Application?

like image 295
kartal Avatar asked Aug 31 '10 15:08

kartal


2 Answers

Add this to the UIElement/FramworkElement from where you do not wish the Alt+F4 to work.

wnd.KeyDown += new KeyEventHandler(wnd_KeyDown);

void wnd_KeyDown(object sender, KeyEventArgs e)
{
    if ( e.Key == Key.System && e.SystemKey == Key.F4)
    {
        e.Handled = true;
    }
}
like image 155
Anant Anand Avatar answered Sep 29 '22 04:09

Anant Anand


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
like image 36
Svisstack Avatar answered Sep 29 '22 04:09

Svisstack