Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
私はWPFフォームを持っています。イベントを処理しKeyUp、リリースされたキーが Escape の場合、それ自体を閉じます。
KeyUp
また、このフォームには、いくつかの Windows フォームをダイアログとして表示するためのボタンがあります。Escape キーも同じように処理します。
子ダイアログで Escape を押すと、両方のウィンドウが閉じます。この場合、子 Windows フォーム ウィンドウだけが閉じると思います。
これを処理する適切な方法は何ですか?
WPFの最も簡単なオプションは、ボタン プロパティIsCancelを に設定することtrueです。次に、フォームを押すESCと閉じられます。
IsCancel
true
ESC
KeyUp イベントのhandled プロパティを true に設定してみてください:
private void myDialogForm_KeyUp(object sender, KeyEventArgs e) { e.Handled = true; }