开发者

Ignore Alt+F4 in WPF Application

开发者 https://www.devze.com 2023-01-14 13:11 出处:网络
How can I ignore Alt+开发者_开发百科F4 in WPF Application?Add this to the UIElement/FramworkElement from where you do not wish the Alt+F4 to work.

How can I ignore Alt+开发者_开发百科F4 in WPF Application?


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;
    }
}


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


Simply use input binding like this in your View(Xaml) File:

<Window.InputBindings>
    <KeyBinding Modifiers="Alt" Key="F4" Command="{Binding Path=ToDelegateCommandThatExecuteNothing}" />
</Window.InputBindings>
0

精彩评论

暂无评论...
验证码 换一张
取 消