Пример #1
0
        public MessageBoxEx(IWin32Window parent, string message, string title, MessageBoxButtons buttons, MessageBoxIcon icon, DefaultButton defaultButton, System.Windows.MessageBoxOptions flags = System.Windows.MessageBoxOptions.None, MessageBoxExOptions extraOptions = null) : this()
        {
            //Set up form
            lblTitle.Content            = title;
            txtDescription.Text         = message;
            txtDescription.TextTrimming = TextTrimming.CharacterEllipsis;
            //Set the buttons according to the buttons parameter.
            this.btns = buttons;
            switch (buttons)
            {
            case MessageBoxButtons.OK:
                //Only OK button should be visible.
                HideButtons(btnAbort, btnIgnoreCancel, btnNo, btnRetry);
                ShowButtons(btnYesOk, btnCancel);
                btnYesOk.Content = "OK";
                break;

            case MessageBoxButtons.OKCancel:
                //Only OK and Cancel button should be visible
                ShowButtons(btnIgnoreCancel, btnYesOk, btnCancel);
                HideButtons(btnAbort, btnNo, btnRetry);
                btnIgnoreCancel.Content = "CANCEL";
                btnYesOk.Content        = "OK";
                break;

            case MessageBoxButtons.AbortRetryIgnore:
                //Only Abort Retry and Ignore buttons should be visible. Not even X button
                ShowButtons(btnRetry, btnIgnoreCancel, btnAbort);
                HideButtons(btnCancel, btnNo, btnYesOk);
                btnIgnoreCancel.Content = "IGNORE";
                break;

            case MessageBoxButtons.YesNoCancel:
                //Only Yes, No and Cancel (plus x) buttons should be visible
                ShowButtons(btnYesOk, btnNo, btnCancel);
                HideButtons(btnAbort, btnIgnoreCancel, btnRetry);
                btnYesOk.Content = "YES";
                break;

            case MessageBoxButtons.YesNo:
                //Only Yes and No buttons should be visible. (not even x button)
                ShowButtons(btnYesOk, btnNo);
                HideButtons(btnRetry, btnIgnoreCancel, btnCancel, btnAbort);
                btnYesOk.Content = "YES";
                break;

            case MessageBoxButtons.RetryCancel:
                //Only retry or cancel buttons should be visible. (not even x)
                ShowButtons(btnRetry, btnIgnoreCancel);
                HideButtons(btnAbort, btnCancel, btnNo, btnYesOk);
                btnIgnoreCancel.Content = "RETRY";
                break;

            default:
                ShowButtons(btnYesOk, btnCancel);
                HideButtons(btnRetry, btnNo, btnIgnoreCancel, btnAbort);
                btnYesOk.Content = "OK";
                break;
            }
            //Set default button
            switch (defaultButton)
            {
            case DefaultButton.OK:
            case DefaultButton.Yes:
                SelectButton(btnYesOk);
                break;

            case DefaultButton.No:
                SelectButton(btnNo);
                break;

            case DefaultButton.Ignore:
            case DefaultButton.Cancel:
                SelectButton(btnIgnoreCancel);
                break;

            case DefaultButton.Abort:
                SelectButton(btnAbort);
                break;

            case DefaultButton.Retry:
                SelectButton(btnRetry);
                break;

            default:
                SelectButton(btnYesOk);
                break;
            }
            //Set up ICON
            switch (icon)
            {
            default:
            case MessageBoxIcon.None:
                break;

            case MessageBoxIcon.Error:
                this.Background           = new SolidColorBrush(Colors.Red);
                txtDescription.Foreground = new SolidColorBrush(Colors.White);
                break;

            case MessageBoxIcon.Warning:
                this.Background           = new SolidColorBrush(Colors.Gold);
                txtDescription.Foreground = new SolidColorBrush(Colors.Black);
                break;

            case MessageBoxIcon.Information:
                this.Background           = new SolidColorBrush(Colors.Green);
                txtDescription.Foreground = new SolidColorBrush(Colors.White);
                break;
            }
            /////TO-DO/////
            /// Extract icons from windows shell.dll or imageres.dll
            ///////////////
            //Set up extended params (background, colors, placement, etc..)
            if (extraOptions != null)
            {
                extraOptions.MessageBox = this;
            }
        }
Пример #2
0
        public static DialogResult Show(IWin32Window owner, string msg, MessageKind kind, MessageBoxExOptions options = null)
        {
            var mbx = new MessageBoxEx(owner, msg,
                                       (kind == MessageKind.Error)?"XKeyboard - Error":(kind == MessageKind.Info)?"XKeyboard - Info": "XKeyboard - Warning",
                                       MessageBoxButtons.OK,
                                       (kind == MessageKind.Info)? MessageBoxIcon.Information : (kind == MessageKind.Warning) ? MessageBoxIcon.Warning : MessageBoxIcon.Error, DefaultButton.OK);

            //mbo.Assign(mbx);    //Assign the msgboxex to its options, which handles the sound and and UI
            if (options != null)
            {
                options.Assign(mbx);
            }
            //Set up mbx parameters and msg box settings according to the parameters passed to this function.
            if (mbx.ShowDialog() == true)   //True only if the form was handled succesfully.
            {
                return(mbx.Result);
            }
            return(System.Windows.Forms.DialogResult.None);
        }