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 @@ namespace ShareX.HelpersLib
public static void CloseOnEscape(this Form form)
{
bool escapePressed = false;
form.KeyPreview = true;
form.KeyDown += (sender, e) =>
{
if (e.KeyCode == Keys.Escape)
{
escapePressed = true;
e.SuppressKeyPress = true;
}
};
form.KeyUp += (sender, e) =>
{
if (e.KeyCode == Keys.Escape)
if (e.KeyCode == Keys.Escape && escapePressed)
{
escapePressed = false;
form.DialogResult = DialogResult.Cancel;
form.Close();
}

View File

@ -609,7 +609,8 @@ namespace ShareX.ScreenCaptureLib
if (IsImageModified)
{
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);
if (dialogResult == DialogResult.Yes)