fixed #7346: Improve CloseOnEscape logic

This commit is contained in:
Jaex 2024-03-21 18:37:32 +03:00
parent d64ae9702f
commit 1a308afdda
2 changed files with 7 additions and 2 deletions

View file

@ -56,20 +56,24 @@ public static void ForceActivate(this Form form)
public static void CloseOnEscape(this Form form) public static void CloseOnEscape(this Form form)
{ {
bool escapePressed = false;
form.KeyPreview = true; form.KeyPreview = true;
form.KeyDown += (sender, e) => form.KeyDown += (sender, e) =>
{ {
if (e.KeyCode == Keys.Escape) if (e.KeyCode == Keys.Escape)
{ {
escapePressed = true;
e.SuppressKeyPress = true; e.SuppressKeyPress = true;
} }
}; };
form.KeyUp += (sender, e) => form.KeyUp += (sender, e) =>
{ {
if (e.KeyCode == Keys.Escape) if (e.KeyCode == Keys.Escape && escapePressed)
{ {
escapePressed = false;
form.DialogResult = DialogResult.Cancel; form.DialogResult = DialogResult.Cancel;
form.Close(); form.Close();
} }

View file

@ -609,7 +609,8 @@ internal bool ShowExitConfirmation()
if (IsImageModified) if (IsImageModified)
{ {
Pause(); Pause();
DialogResult dialogResult = MessageBox.Show(this, Resources.RegionCaptureForm_SaveChangesBeforeClosingEditor, Resources.RegionCaptureForm_ShowExitConfirmation_ShareXImageEditor, DialogResult dialogResult = MessageBox.Show(this, Resources.RegionCaptureForm_SaveChangesBeforeClosingEditor,
Resources.RegionCaptureForm_ShowExitConfirmation_ShareXImageEditor,
MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question); MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question);
if (dialogResult == DialogResult.Yes) if (dialogResult == DialogResult.Yes)