Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to close only single dialog on ESC key in WPF/WinForms?

I have a WPF form. It handles the KeyUp event and if the released key was Escape, it closes itself.

Also this form has a button to show some Windows Form as a dialog. It does handle the Escape key in the same way.

What happens is that when I press Escape when in the child dialog, both windows close. I expect only the child Windows Forms window to close in this case.

What's the proper way to handle this?

like image 225
Mikhail Orlov Avatar asked Apr 16 '10 11:04

Mikhail Orlov


1 Answers

The easiest option for WPF is set the button property IsCancel to true. Then if you press ESC the form would be closed.

like image 142
akrisanov Avatar answered Nov 15 '22 02:11

akrisanov