private void SettingsUI_FormClosing(object sender, FormClosingEventArgs e) { if (saved) { DialogResult = CurrentState == initState ? DialogResult.Cancel : DialogResult.OK; return; } if (!CurrentState.Equals(initState)) { var res = MessageBox.Show(Language.Data.ConfigDiscardMsgTitel, Language.Data.ConfigDiscardMsgText, MessageBoxButtons.OKCancel, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button2); switch (res) { case DialogResult.OK: DialogResult = DialogResult.Cancel; return; default: if (e.CloseReason == CloseReason.UserClosing) { e.Cancel = true; } break; } } DialogResult = DialogResult.OK; }