예제 #1
0
        private static void InitIcon(MsgIcon icon)
        {
            switch (icon)
            {
            case MsgIcon.Application:
                _msgBox.PanelIconPic.Image = SystemIcons.Application.ToBitmap();
                break;

            case MsgIcon.Exclamation:
                _msgBox.PanelIconPic.Image = SystemIcons.Exclamation.ToBitmap();
                break;

            case MsgIcon.Error:
                _msgBox.PanelIconPic.Image = SystemIcons.Error.ToBitmap();
                break;

            case MsgIcon.Info:
                _msgBox.PanelIconPic.Image = SystemIcons.Information.ToBitmap();
                break;

            case MsgIcon.Question:
                _msgBox.PanelIconPic.Image = SystemIcons.Question.ToBitmap();
                break;

            case MsgIcon.Shield:
                _msgBox.PanelIconPic.Image = SystemIcons.Shield.ToBitmap();
                break;

            case MsgIcon.Warning:
                _msgBox.PanelIconPic.Image = SystemIcons.Warning.ToBitmap();
                break;
            }
        }
예제 #2
0
 public MsgPack(string message, string caption, MsgButton button, MsgIcon icon, MsgResult defaultResult)
 {
     Message       = message;
     Caption       = caption;
     Button        = button;
     Icon          = icon;
     DefaultResult = defaultResult;
 }
예제 #3
0
        public static MsgResult Show(string message, string caption = null, MsgButton button = MsgButton.OK,
                                     MsgIcon icon = MsgIcon.None, MsgResult defaultResult    = MsgResult.None, Window owner = null)
        {
            msgBox = new WPFMessageBoxControl(owner);
            MsgPack messagePack = new MsgPack(message, caption, button, icon, defaultResult);
            WPFMessageBoxViewModel viewmodel = new WPFMessageBoxViewModel(messagePack);

            msgBox.DataContext = viewmodel;
            PlayMessageBeep(icon);
            msgBox.ShowDialog();
            return(Result);
        }
예제 #4
0
    public static MsgResult Show(
        string mainInstruction,
        string content,
        MsgIcon icon,
        MsgButtons buttons,
        MsgResult defaultButton = MsgResult.None)
    {
        try
        {
            using (TaskDialog <MsgResult> td = new TaskDialog <MsgResult>())
            {
                td.AllowCancel   = false;
                td.DefaultButton = defaultButton;
                td.MainIcon      = icon;

                if (content == null)
                {
                    if (mainInstruction.Length < 80)
                    {
                        td.MainInstruction = mainInstruction;
                    }
                    else
                    {
                        td.Content = mainInstruction;
                    }
                }
                else
                {
                    td.MainInstruction = mainInstruction;
                    td.Content         = content;
                }
                if (buttons == MsgButtons.OkCancel)
                {
                    td.AddButton("OK", MsgResult.OK);
                    td.AddButton("Cancel", MsgResult.Cancel);
                }
                else
                {
                    td.CommonButtons = buttons;
                }
                return(td.Show());
            }
        }
        catch (Exception e)
        {
            return((MsgResult)MessageBox.Show(e.GetType().Name + "\n\n" + e.Message + "\n\n" + e,
                                              Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error));
        }
    }
예제 #5
0
        private static void PlayMessageBeep(MsgIcon icon)
        {
            switch (icon)
            {
            case MsgIcon.Error:
                SystemSounds.Hand.Play();
                break;

            case MsgIcon.Warning:
                SystemSounds.Exclamation.Play();
                break;

            case MsgIcon.Question:
                SystemSounds.Question.Play();
                break;

            case MsgIcon.Information:
                SystemSounds.Asterisk.Play();
                break;
            }
        }
예제 #6
0
        public void Show(string title, string msg, MsgIcon icon, MsgBtns btns, MsgBoxCloseCallBack callBack)
        {
            if (callBack != null)
            {
                _CallBack = callBack;
            }

            this.msgBlock.Text = msg;
            this.Title         = title;

            switch (icon)
            {
            case MsgIcon.Information:
                this.imgIcon.Source = LoadImage("Images/Message.png");
                break;

            case MsgIcon.StopSign:
                this.imgIcon.Source = LoadImage("Images/StopSign.png");
                break;

            case MsgIcon.Exclamation:
                this.imgIcon.Source = LoadImage("Images/Exclamation.png");
                break;

            case MsgIcon.Question:
                this.imgIcon.Source = LoadImage("Images/Question.png");
                break;

            case MsgIcon.None:
                break;

            default:
                break;
            }

            switch (btns)
            {
            case MsgBtns.OK:
                CreateButtons(new KeyValuePair <string, string>[] { new KeyValuePair <string, string>("OK", "确定") });
                break;

            case MsgBtns.Cancel:
                CreateButtons(new KeyValuePair <string, string>[] { new KeyValuePair <string, string>("Cancel", "取消") });
                break;

            case MsgBtns.OKCancel:
                CreateButtons(new KeyValuePair <string, string>[]
                              { new KeyValuePair <string, string>("OK", "确定"),
                                new KeyValuePair <string, string>("Cancel", "取消") });
                break;

            case MsgBtns.YesNo:
                CreateButtons(new KeyValuePair <string, string>[]
                              { new KeyValuePair <string, string>("Yes", "是"),
                                new KeyValuePair <string, string>("No", "否") });
                break;

            case MsgBtns.YesNoCancel:
                CreateButtons(new KeyValuePair <string, string>[]
                              { new KeyValuePair <string, string>("Yes", "是"),
                                new KeyValuePair <string, string>("No", "否"),
                                new KeyValuePair <string, string>("Cancel", "取消") });
                break;

            case MsgBtns.OKCancelApply:
                CreateButtons(new KeyValuePair <string, string>[]
                              { new KeyValuePair <string, string>("OK", "确定"),
                                new KeyValuePair <string, string>("Cancel", "取消"),
                                new KeyValuePair <string, string>("Apply", "应用") });
                break;

            case MsgBtns.RetryCancel:
                CreateButtons(new KeyValuePair <string, string>[]
                              { new KeyValuePair <string, string>("Retry", "重试"),
                                new KeyValuePair <string, string>("Cancel", "取消") });
                break;

            case MsgBtns.AbortRetryIgnore:
                CreateButtons(new KeyValuePair <string, string>[]
                              { new KeyValuePair <string, string>("Abort", "取消"),
                                new KeyValuePair <string, string>("Retry", "重试"),
                                new KeyValuePair <string, string>("Ignore", "忽略") });
                break;
            }
            base.Show();
        }
예제 #7
0
 public void Show(string title, string msg, MsgIcon icon, MsgBoxCloseCallBack callBack)
 {
     Show(title, msg, icon, MsgBtns.OK, callBack);
 }
예제 #8
0
 public void Add(string title, string message, MsgIcon icon, bool forceactivate = true)
 {
     BitmapImage icon2 = null;
     switch (icon)
     {
         case MsgIcon.Error:
             icon2 = Utilities.LoadBitmap("..\\..\\Resources\\error.png");
             break;
         case MsgIcon.Info:
             icon2 = Utilities.LoadBitmap("..\\..\\Resources\\info.png");
             break;
     }
     _messages.Add(new OutputWindowMessage
     {
         Title = title,
         Description = message,
         Icon = icon2
     });
     if (forceactivate)
     {
         RaiseMessageAdded();
     }
 }
예제 #9
0
        public static DialogResult Show(string message, string title, Buttons buttons, MsgIcon icon)
        {
            _msgBox = new MsgBox();
            _msgBox.PanelHeaderLblMessage.Text = message;
            _msgBox.PanelHeaderLblTitle.Text   = title;
            _msgBox.Text = title;

            InitButtons(buttons);
            InitIcon(icon);

            _msgBox.Size = MessageSize(message);
            _msgBox.ShowDialog();

            return(_dialogResult);
        }
예제 #10
0
        public static DialogResult Show(string message, string title, Buttons buttons, MsgIcon icon, Animate style)
        {
            _msgBox = new MsgBox();
            _msgBox.PanelHeaderLblMessage.Text = message;
            _msgBox.PanelHeaderLblTitle.Text   = title;
            _msgBox.Text   = title;
            _msgBox.Height = 0;

            InitButtons(buttons);
            InitIcon(icon);

            Size formSize = MessageSize(message);

            switch (style)
            {
            case Animate.SlideDown:
                _msgBox.Size             = new Size(formSize.Width, 0);
                _msgBox.TmrAnim.Interval = 1;
                _msgBox.TmrAnim.Tag      = new AnimateMsgBox(formSize, style);
                break;

            case Animate.FadeIn:
                _msgBox.Size             = formSize;
                _msgBox.Opacity          = 0;
                _msgBox.TmrAnim.Interval = 20;
                _msgBox.TmrAnim.Tag      = new AnimateMsgBox(formSize, style);
                break;

            case Animate.ZoomIn:
                _msgBox.Size             = new Size(formSize.Width + 100, formSize.Height + 100);
                _msgBox.TmrAnim.Tag      = new AnimateMsgBox(formSize, style);
                _msgBox.TmrAnim.Interval = 1;
                break;
            }

            _msgBox.Size = MessageSize(message);
            _msgBox.TmrAnim.Start();
            _msgBox.ShowDialog();

            return(_dialogResult);
        }
예제 #11
0
 public MsgResult ShowMessageBox(string message, string caption = null, MsgButton button = MsgButton.OK,
                                 MsgIcon icon = MsgIcon.None, MsgResult defaultResult    = MsgResult.None, Window owner = null)
 {
     return(WPFMessageBox.Show(message, caption, button, icon, defaultResult, owner));
 }
예제 #12
0
        static MsgBox GetMsgBox(string message, string title = "Title", string[] options = null, MsgIcon icon = 0)
        {
            if (options == null || options.Length == 0)
            {
                options = new string[] { "OK" }
            }
            ;

            MsgBox msgBox = new MsgBox
            {
                MinimumSize = new Size(100, 0),
                Text        = title
            };

            Label messageLbl = new Label
            {
                Top         = 20,
                AutoSize    = true,
                Left        = 12,
                MaximumSize = new Size(350, 0),
                Text        = message,
                Font        = msgBox.Font
            };

            messageLbl.Size = messageLbl.PreferredSize;

            msgBox.Controls.Add(messageLbl);

            if (icon != 0)
            {
                PictureBox img = new PictureBox
                {
                    Location = new Point(12, Math.Max(12, (messageLbl.Top + messageLbl.Bottom) / 2 - messageLbl.Height / 2)),
                    Size     = new Size(32, 32)
                };

                messageLbl.Left = img.Right + 6;

                // Assign message box icon and play sound
                if (icon == MsgIcon.ERROR)
                {
                    img.Image = Properties.Resources.Error;
                    SystemSounds.Hand.Play();
                }
                else if (icon == MsgIcon.EXCL)
                {
                    img.Image = Properties.Resources.Exclamation;
                    SystemSounds.Exclamation.Play();
                }
                else if (icon == MsgIcon.TICK)
                {
                    img.Image = Properties.Resources.Tick;
                    SystemSounds.Asterisk.Play();
                }
                else
                {
                    img.Image = Properties.Resources.Information;
                    SystemSounds.Asterisk.Play();
                }

                msgBox.Controls.Add(img);
            }

            //messageLbl.Left = msgBox.PreferredSize.Width + 6;

            int btnRight = msgBox.PreferredSize.Width + 6;
            //int btnTop = msgBox.PreferredSize.Height + 6;
            int btnTop = messageLbl.Bottom + 20;

            for (int i = 0; i < options.Length; i++)
            {
                Button btn = new Button
                {
                    FlatStyle = FlatStyle.Flat,
                    Top       = btnTop,
                    Size      = new Size(99, 36),
                    Left      = btnRight - ((99 + 6) * (options.Length - i)),
                    Text      = options[i]
                };

                btn.FlatAppearance.BorderSize = 0;

                btn.Click += (s, e) =>
                {
                    msgBox.result = btn.Text;
                    msgBox.Close();
                };

                msgBox.Controls.Add(btn);
            }

            // Fitting form to controls
            msgBox.Width  = msgBox.PreferredSize.Width + 6;
            msgBox.Height = msgBox.PreferredSize.Height + 6;

            return(msgBox);
        }
예제 #13
0
        public static string ShowWait(string message, string title = "Title", string[] options = null, MsgIcon icon = 0)
        {
            var msgBox = GetMsgBox(message, title, options, icon);

            // Show message box and return the result.
            msgBox.ShowDialog();
            return(msgBox.result);
        }
예제 #14
0
        public static void Show(string message, Action <string> onReturn, string title = "Title", string[] options = null, MsgIcon icon = 0)
        {
            var msgBox = GetMsgBox(message, title, options, icon);

            msgBox.FormClosing += (s, e) =>
            {
                onReturn(msgBox.result);
            };

            msgBox.Show();
        }