/// <summary> /// Shows a message including the "do not show this again" checkbox. /// If that checkbox has been checked in the past, the message is not shown at all. /// Note that "do not show this again" is ignored unless the user also pressed OK or Yes. /// </summary> /// <param name="owner">The owner form.</param> /// <param name="message">The message to show.</param> /// <param name="caption">The dialog caption.</param> /// <param name="buttons">The buttons to show in the dialog.</param> /// <param name="icon">The icon to show in the dialog.</param> /// <param name="messageKey">The message key (used to mark messages that are not to be shown, in the settings file).</param> /// <returns>The dialog result.</returns> public static DialogResult Show( IWin32Window owner, Caption caption, string message, MessageBoxButtons buttons, MessageBoxIcon icon, MessageKey messageKey) { using (MessageForm mf = new MessageForm()) { DialogResult res = DialogResult.Cancel; mf.Text = c_captions[caption]; mf.lblMessage.Text = ValidateNewlines(message); switch (buttons) { case MessageBoxButtons.OK: mf.btnOk.Text = Strings.MessageForm.ButtonOK; mf.btnOk.DialogResult = DialogResult.OK; mf.btnNo.Visible = mf.btnCancel.Visible = false; mf.AcceptButton = mf.btnOk; res = DialogResult.OK; break; case MessageBoxButtons.OKCancel: mf.btnOk.Text = Strings.MessageForm.ButtonOK; mf.btnOk.DialogResult = DialogResult.OK; mf.btnCancel.Text = Strings.MessageForm.ButtonCancel; mf.btnCancel.DialogResult = DialogResult.Cancel; mf.btnNo.Visible = false; mf.AcceptButton = mf.btnOk; mf.CancelButton = mf.btnCancel; res = DialogResult.OK; break; case MessageBoxButtons.AbortRetryIgnore: mf.btnOk.Text = Strings.MessageForm.ButtonAbort; mf.btnOk.DialogResult = DialogResult.Abort; mf.btnNo.Text = Strings.MessageForm.ButtonRetry; mf.btnNo.DialogResult = DialogResult.Retry; mf.btnCancel.Text = Strings.MessageForm.ButtonIgnore; mf.btnCancel.DialogResult = DialogResult.Ignore; messageKey = MessageKey.None; // do not allow "do not show this again" break; case MessageBoxButtons.YesNoCancel: mf.btnOk.Text = Strings.MessageForm.ButtonYes; mf.btnOk.DialogResult = DialogResult.Yes; mf.btnNo.Text = Strings.MessageForm.ButtonNo; mf.btnNo.DialogResult = DialogResult.No; mf.btnCancel.Text = Strings.MessageForm.ButtonCancel; mf.btnCancel.DialogResult = DialogResult.Cancel; mf.AcceptButton = mf.btnOk; mf.CancelButton = mf.btnCancel; res = DialogResult.Yes; break; case MessageBoxButtons.YesNo: mf.btnOk.Text = Strings.MessageForm.ButtonYes; mf.btnOk.DialogResult = DialogResult.Yes; mf.btnNo.Text = Strings.MessageForm.ButtonNo; mf.btnNo.DialogResult = DialogResult.No; mf.btnCancel.Visible = false; mf.AcceptButton = mf.btnOk; res = DialogResult.Yes; break; case MessageBoxButtons.RetryCancel: mf.btnOk.Text = Strings.MessageForm.ButtonRetry; mf.btnOk.DialogResult = DialogResult.Retry; mf.btnCancel.Text = Strings.MessageForm.ButtonCancel; mf.btnCancel.DialogResult = DialogResult.Cancel; mf.btnNo.Visible = false; mf.CancelButton = mf.btnCancel; messageKey = MessageKey.None; // do no allow "do not show this again" break; default: Debug.Assert(false); return(DialogResult.Cancel); } switch (icon) { case MessageBoxIcon.None: mf.picIcon.Visible = false; break; case MessageBoxIcon.Error: //case MessageBoxIcon.Hand: //case MessageBoxIcon.Stop: mf.picIcon.Image = global::FlexReportDesignerApp.Properties.Resources.error32; break; case MessageBoxIcon.Question: mf.picIcon.Image = global::FlexReportDesignerApp.Properties.Resources.question32; break; case MessageBoxIcon.Exclamation: //case MessageBoxIcon.Warning: mf.picIcon.Image = global::FlexReportDesignerApp.Properties.Resources.warn32; break; case MessageBoxIcon.Information: //case MessageBoxIcon.Asterisk: mf.picIcon.Image = global::FlexReportDesignerApp.Properties.Resources.info32; break; default: Debug.Assert(false); return(DialogResult.Cancel); } bool show; if (messageKey != MessageKey.None) { mf.chkDoNotShowAgain.Visible = true; show = !GetMessageSuppressed(messageKey); } else { mf.chkDoNotShowAgain.Visible = false; show = true; } if (show) { if (owner == null) { mf.StartPosition = FormStartPosition.CenterScreen; } show_dialog: res = mf.ShowDialog(owner); // make sure: if (res == DialogResult.Abort) { DialogResult abort = Show(mf, Caption.Confirm, Strings.MessageForm.ConfirmAbort, MessageBoxButtons.YesNo, MessageBoxIcon.Hand, MessageKey.WarnOnAbort); if (abort != DialogResult.Yes) { goto show_dialog; } // ABORT: Program.Exit(Program.ExitCodes.UserAbort); // ooops } } // else we already set the default result if (messageKey != MessageKey.None && mf.chkDoNotShowAgain.Checked && (res == DialogResult.OK || res == DialogResult.Yes)) { SetMessageSuppressed(messageKey, true); } return(res); } }
// show the dialog /// <summary> /// Shows the options form, initializing it with current values, /// and saving any changes when the form closes on OK. /// </summary> /// <param name="startTabName"></param> /// <returns></returns> public DialogResult ShowDialog(string startTabName) { using (OptionsForm dlg = new OptionsForm()) { dlg.MainForm = _owner; // get designer var designer = _owner.FlexDesigner; dlg.Theme = _owner.Theme; // Designer options: dlg.LoadDesignerPanePrefs(); // bool assoc = FileAssocHelper.IsAssociated(); dlg.FileAssociateFLXR = assoc; // dlg.LoadOnStartup = _owner._loadOnStartUp; dlg.RestoreEditorSettings = _owner._restoreEditorSettings; dlg.EmbedImages = _owner._embedImages; dlg.AutoSave = _owner._autoSave; dlg.OpenExportedFile = _owner._openExportedFile; dlg.CategorizeProperties = _owner.CategorizeProperties; dlg.SortReportList = _owner.SortReportList; dlg.SyntaxCheck = _owner._syntaxCheck; dlg.SyntaxColoring = _owner._syntaxColoring; dlg.ScriptEditorFont = _owner._scriptEditorFont; dlg.IsolationLevel = _owner._isolationLevel; dlg.InsertLegacyField = _owner._insertLegacyField; dlg.InsertLegacyChart = _owner._insertLegacyChart; // suppressed messages: dlg.WarnImportCrystalRASNotAvailable = !MessageForm.GetMessageSuppressed(MessageForm.MessageKey.WarnImportCrystalRASNotAvailable); dlg.WarnAppIn64bitMode = !MessageForm.GetMessageSuppressed(MessageForm.MessageKey.WarnAppIn64bitMode); // start tab: dlg.StartTabName = string.IsNullOrEmpty(startTabName) ? _owner._optionsStartTabName : startTabName; // show dialog DialogResult dr = dlg.ShowDialog(_owner); if (dr != DialogResult.OK) { return(dr); } // apply changes to app _owner.Theme = dlg.Theme; _owner._optionsStartTabName = dlg.StartTabName; // dlg.SaveDesignerPanePrefs(); // _owner._loadOnStartUp = dlg.LoadOnStartup; _owner._restoreEditorSettings = dlg.RestoreEditorSettings; _owner._embedImages = dlg.EmbedImages; _owner._autoSave = dlg.AutoSave; _owner._openExportedFile = dlg.OpenExportedFile; _owner.CategorizeProperties = dlg.CategorizeProperties; _owner._syntaxCheck = dlg.SyntaxCheck; _owner._syntaxColoring = dlg.SyntaxColoring; _owner._scriptEditorFont = dlg.ScriptEditorFont; _owner.SortReportList = dlg.SortReportList; _owner._isolationLevel = dlg.IsolationLevel; _owner._insertLegacyField = dlg.InsertLegacyField; _owner._insertLegacyChart = dlg.InsertLegacyChart; // suppressed messages: MessageForm.SetMessageSuppressed(MessageForm.MessageKey.WarnImportCrystalRASNotAvailable, !dlg.WarnImportCrystalRASNotAvailable); MessageForm.SetMessageSuppressed(MessageForm.MessageKey.WarnAppIn64bitMode, !dlg.WarnAppIn64bitMode); // save changes SaveAppState(); if (dlg.FileAssociateFLXR != assoc) { FileAssocHelper.Associate(dlg.FileAssociateFLXR); } // done return(dr); } }