Esempio n. 1
0
        /// <summary>
        /// Shows a metro-styles message notification into the specified owner window.
        /// </summary>
        /// <param name="owner"></param>
        /// <param name="message"></param>
        /// <param name="title"></param>
        /// <param name="buttons"></param>
        /// <param name="icon"></param>
        /// <param name="defaultbutton"></param>
        /// <returns></returns>
        public static DialogResult Show(IWin32Window owner, String message, String title, MessageBoxButtons buttons, MessageBoxIcon icon, MessageBoxDefaultButton defaultbutton)
        {
            DialogResult result = DialogResult.None;
            Form         form   = (owner == null) ? null : ((Form)owner);

            if (icon != MessageBoxIcon.Hand)
            {
                if (icon != MessageBoxIcon.Question)
                {
                    if (icon != MessageBoxIcon.Exclamation)
                    {
                        SystemSounds.Asterisk.Play();
                    }
                    else
                    {
                        SystemSounds.Exclamation.Play();
                    }
                }
                else
                {
                    SystemSounds.Beep.Play();
                }
            }
            else
            {
                SystemSounds.Hand.Play();
            }
            if (_control != null)
            {
                _control = null;
            }
            _control                          = new WellsMetroMessageBoxControl();
            _control.BackColor                = ((form == null) ? System.Drawing.Color.CadetBlue : form.BackColor);
            _control.Properties.Buttons       = buttons;
            _control.Properties.DefaultButton = defaultbutton;
            _control.Properties.Icon          = icon;
            _control.Properties.Message       = message;
            _control.Properties.Title         = title;
            _control.Padding                  = new Padding(0, 0, 0, 0);
            _control.ShowInTaskbar            = false;
            _control.Size                     = ((form == null) ? new System.Drawing.Size(500, 270) : new System.Drawing.Size(form.Size.Width - 16, _control.Height));
            int x = Convert.ToInt32(Math.Ceiling((decimal)(Screen.PrimaryScreen.WorkingArea.Size.Width / 2 - _control.Size.Width / 2)));
            int y = Convert.ToInt32(Math.Ceiling((decimal)(Screen.PrimaryScreen.WorkingArea.Size.Height / 2 - _control.Size.Height / 2)));

            _control.Location = ((form == null) ? new System.Drawing.Point(x, y) : new System.Drawing.Point(form.Location.X + 8, form.Location.Y + (form.Height - _control.Height) / 2));
            _control.ArrangeApperance();
            Convert.ToInt32(Math.Floor((double)_control.Size.Height * 0.28));
            _control.ShowDialog();
            _control.BringToFront();
            _control.SetDefaultButton();
            Action <WellsMetroMessageBoxControl> action = new Action <WellsMetroMessageBoxControl>(ModalState);
            IAsyncResult asyncResult = action.BeginInvoke(_control, null, action);
            bool         flag        = false;

            try
            {
                while (!asyncResult.IsCompleted)
                {
                    Thread.Sleep(1);
                    Application.DoEvents();
                }
            }
            catch
            {
                flag = true;
                if (!asyncResult.IsCompleted)
                {
                    try
                    {
                        asyncResult = null;
                    }
                    catch
                    {
                    }
                }
            }
            if (!flag)
            {
                result = _control.Result;
                _control.Dispose();
                _control = null;
            }
            return(result);
        }
Esempio n. 2
0
 private static void ModalState(WellsMetroMessageBoxControl control)
 {
     while (control.Visible)
     {
     }
 }