/// <summary>
        /// This constructor initialize a new instance of this class.
        /// </summary>
        /// <param name="owner">
        /// The owner of the dialog box.
        /// </param>
        /// <param name="message">
        /// The message to be displayed.
        /// </param>
        /// <param name="caption">
        /// The dialog box caption to be used.
        /// </param>
        /// <param name="buttons">
        /// The set of flags describing the used buttons.
        /// </param>
        /// <param name="symbol">
        /// The dialog box symbol to be shown.
        /// </param>
        /// <param name="options">
        /// The list of additional dialog box options.
        /// </param>
        public DialogBox(Window owner, String message, String caption, DialogButton buttons, DialogSymbol symbol, DialogOption[] options)
        {
            base.MinHeight = 180;
            base.MaxHeight = SystemParameters.WorkArea.Height;
            base.MinWidth  = 550; // Don't change! Otherwise the link is covered by buttons if all of them are visible.
            base.MaxWidth  = 800;
            base.Height    = 180;
            base.Width     = 550;

            this.Message = this.FixMessage(message);
            base.Title   = this.FixCaption(owner, caption);
            this.Symbol  = this.GetSymbol(symbol);
            this.Buttons = buttons;
            this.Result  = Dialogs.DialogResult.None;

            this.labels = DefaultButtonLabels.CreateLabels();

            this.ApplyOptions(options);
            this.ApplyDefaults(options);

            this.InitializeComponent();

            base.Owner = owner;
            base.WindowStartupLocation = (base.Owner is null) ? WindowStartupLocation.CenterScreen : WindowStartupLocation.CenterOwner;
            base.ShowInTaskbar         = (base.Owner is null ? true : false);

            base.DataContext = this;
        }
        private void ApplyOptions(DialogOption[] options)
        {
            if (options is null || options.Length < 1)
            {
                return;
            }

            foreach (DialogOption option in options)
            {
                if (!DefaultButtonLabels.IsDefaultButtonLabel(option.Button, option.Label))
                {
                    this.labels[option.Button] = option.Label;
                }
            }
        }
Esempio n. 3
0
        public static DialogResult Show(string text, string caption, MessageBoxButtons buttons, MessageBoxIcon icon, MessageBoxDefaultButton defaultButton)
        {
            DialogResult result;

            DialogResult[] resultArray;
            MakeButtonCache();
            if (string.IsNullOrEmpty(text))
            {
                text = caption;
            }
            if (text == null)
            {
                text = string.Empty;
            }
            bool bMultiLine = (text.Length > 0x10) || (text.IndexOf('\n') >= 0);

            switch (buttons)
            {
            case MessageBoxButtons.OK:
                resultArray = new DialogResult[] { DialogResult.OK };
                break;

            case MessageBoxButtons.OKCancel:
                resultArray = new DialogResult[] { DialogResult.OK, DialogResult.Cancel };
                break;

            case MessageBoxButtons.AbortRetryIgnore:
                resultArray = new DialogResult[] { DialogResult.Abort, DialogResult.Retry, DialogResult.Ignore };
                break;

            case MessageBoxButtons.YesNoCancel:
                resultArray = new DialogResult[] { DialogResult.Yes, DialogResult.No, DialogResult.Cancel };
                break;

            case MessageBoxButtons.YesNo:
                resultArray = new DialogResult[] { DialogResult.Yes, DialogResult.No };
                break;

            case MessageBoxButtons.RetryCancel:
                resultArray = new DialogResult[] { DialogResult.Retry, DialogResult.Cancel };
                break;

            default:
                throw new ArgumentOutOfRangeException("buttons");
            }
            if (defaultButton == MessageBoxDefaultButton.Button1)
            {
                result = resultArray[0];
            }
            else if ((defaultButton == MessageBoxDefaultButton.Button2) && (resultArray.Length > 1))
            {
                result = resultArray[1];
            }
            else if ((defaultButton == MessageBoxDefaultButton.Button3) && (resultArray.Length > 2))
            {
                result = resultArray[2];
            }
            else
            {
                result = ~DialogResult.None;
            }
            for (int i = 0; i < resultArray.Length; i++)
            {
                DialogResult result2 = resultArray[i];
                string       str;
                DefaultButtonLabels.TryGetValue(result2, out str);
                m_yesNoCancel[i].Set(str, result2);
            }
            Resco.Controls.MessageBox.MenuItem[] items = new Resco.Controls.MessageBox.MenuItem[resultArray.Length];
            for (int j = 0; j < resultArray.Length; j++)
            {
                items[j] = m_yesNoCancel[j];
            }
            return(PopupMenuForm.Show <DialogResult>(icon, bMultiLine, text, result, items));
        }
Esempio n. 4
0
 /// <summary>
 /// The constructor to apply provided <paramref name="button"/>.
 /// </summary>
 /// <remarks>
 /// The provided button's default behaviour is applied according value of
 /// <paramref name="isDefault"/> as well as its default label is replaced by
 /// provided <paramref name="label"/>.
 /// </remarks>
 /// <param name="button">
 /// The button to be used.
 /// </param>
 /// <param name="label">
 /// The label to be used.
 /// </param>
 /// <param name="isDefault">
 /// True to enable default behaviour and false to disable it.
 /// </param>
 public DialogOption(DialogButton button, String label, Boolean isDefault)
 {
     this.Button    = button;
     this.Label     = label ?? DefaultButtonLabels.LabelFor(button);
     this.IsDefault = isDefault;
 }