tags:

views:

160

answers:

2

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?

+1  A: 

Try setting the KeyUp event's handled property equal to true:

private void myDialogForm_KeyUp(object sender, KeyEventArgs e)
{
    e.Handled = true;
}
smoore
+3  A: 

WPF. The easiest option. You can put on the desired button to the form and set the property IsCancel = true. If you press ESC form closes.

Anry
Yes, that was the right way to go, thank you.
Mikhail Orlov