コード例 #1
0
 private static void ModalState(MetroMessageBoxControl control)
 {
     while (control.Visible)
     {
     }
 }
コード例 #2
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>
        /// <param name="height" optional=211></param>
        /// <param name="noSound" optional = false>Set to true to disable sound spawn when dialog show</param>
        /// <returns></returns>
        public static DialogResult Show(IWin32Window owner, String message, String title, MessageBoxButtons buttons, MessageBoxIcon icon, MessageBoxDefaultButton defaultbutton, int height, Boolean noSound = false)
        {
            DialogResult _result = DialogResult.None;

            if (owner != null)
            {
                Form _owner = (owner as Form == null) ? ((UserControl)owner).ParentForm : (Form)owner;

                //int _minWidth = 500;
                //int _minHeight = 350;

                //if (_owner.Size.Width < _minWidth ||
                //    _owner.Size.Height < _minHeight)
                //{
                //    if (_owner.Size.Width < _minWidth && _owner.Size.Height < _minHeight) {
                //            _owner.Size = new Size(_minWidth, _minHeight);
                //    }
                //    else
                //    {
                //        if (_owner.Size.Width < _minWidth) _owner.Size = new Size(_minWidth, _owner.Size.Height);
                //        else _owner.Size = new Size(_owner.Size.Width, _minHeight);
                //    }

                //    int x = Convert.ToInt32(Math.Ceiling((decimal)(Screen.PrimaryScreen.WorkingArea.Size.Width / 2) - (_owner.Size.Width / 2)));
                //    int y = Convert.ToInt32(Math.Ceiling((decimal)(Screen.PrimaryScreen.WorkingArea.Size.Height / 2) - (_owner.Size.Height / 2)));
                //    _owner.Location = new Point(x, y);
                //}

                if (!noSound)
                {
                    switch (icon)
                    {
                    case MessageBoxIcon.Error:
                        SystemSounds.Hand.Play(); break;

                    case MessageBoxIcon.Exclamation:
                        SystemSounds.Exclamation.Play(); break;

                    case MessageBoxIcon.Question:
                        SystemSounds.Beep.Play(); break;

                    default:
                        SystemSounds.Asterisk.Play(); break;
                    }
                }


                MetroMessageBoxControl _control = new MetroMessageBoxControl();
                _control.BackColor                = _owner.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.ControlBox    = false;
                _control.ShowInTaskbar = false;
                _control.TopMost       = true;
                //_owner.Controls.Add(_control);
                //if (_owner is IMetroForm)
                //{
                //    //if (((MetroForm)_owner).DisplayHeader)
                //    //{
                //    //    _offset += 30;
                //    //}
                //    _control.Theme = ((MetroForm)_owner).Theme;
                //    _control.Style = ((MetroForm)_owner).Style;
                //}

                _control.Size     = new Size(_owner.Size.Width, height);
                _control.Location = new Point(_owner.Location.X, _owner.Location.Y + (_owner.Height - _control.Height) / 2);
                _control.ArrangeApperance();
                int _overlaySizes = Convert.ToInt32(Math.Floor(_control.Size.Height * 0.28));
                //_control.OverlayPanelTop.Size = new Size(_control.Size.Width, _overlaySizes - 30);
                //_control.OverlayPanelBottom.Size = new Size(_control.Size.Width, _overlaySizes);

                _control.ShowDialog();
                _control.BringToFront();
                _control.SetDefaultButton();

                Action <MetroMessageBoxControl> _delegate = new Action <MetroMessageBoxControl>(ModalState);
                IAsyncResult _asyncresult = _delegate.BeginInvoke(_control, null, _delegate);
                bool         _cancelled   = false;

                try
                {
                    while (!_asyncresult.IsCompleted)
                    {
                        Thread.Sleep(1); Application.DoEvents();
                    }
                }
                catch
                {
                    _cancelled = true;

                    if (!_asyncresult.IsCompleted)
                    {
                        try { _asyncresult = null; }
                        catch { }
                    }

                    _delegate = null;
                }

                if (!_cancelled)
                {
                    _result = _control.Result;
                    //_owner.Controls.Remove(_control);
                    _control.Dispose(); _control = null;
                }
            }

            return(_result);
        }
コード例 #3
0
        /// <summary>
        /// Shows the specified owner.
        /// </summary>
        /// <param name="owner">The owner.</param>
        /// <param name="message">The message.</param>
        /// <param name="title">The title.</param>
        /// <param name="buttons">The buttons.</param>
        /// <param name="icon">The icon.</param>
        /// <param name="defaultbutton">The defaultbutton.</param>
        /// <param name="inputValue">The input value.</param>
        /// <param name="height">The height.</param>
        /// <returns>DialogResult.</returns>
        public static DialogResult Show(IWin32Window owner, String message, String title, MessageBoxButtons buttons, MessageBoxIcon icon, MessageBoxDefaultButton defaultbutton, ref string inputValue, int height = defaultHeight)
        {
            DialogResult _result = DialogResult.None;

            if (owner != null)
            {
                Form _owner = (owner as Form == null) ? ((UserControl)owner).ParentForm : (Form)owner;

                //int _minWidth = 500;
                //int _minHeight = 350;

                //if (_owner.Size.Width < _minWidth ||
                //    _owner.Size.Height < _minHeight)
                //{
                //    if (_owner.Size.Width < _minWidth && _owner.Size.Height < _minHeight) {
                //            _owner.Size = new Size(_minWidth, _minHeight);
                //    }
                //    else
                //    {
                //        if (_owner.Size.Width < _minWidth) _owner.Size = new Size(_minWidth, _owner.Size.Height);
                //        else _owner.Size = new Size(_owner.Size.Width, _minHeight);
                //    }

                //    int x = Convert.ToInt32(Math.Ceiling((decimal)(Screen.PrimaryScreen.WorkingArea.Size.Width / 2) - (_owner.Size.Width / 2)));
                //    int y = Convert.ToInt32(Math.Ceiling((decimal)(Screen.PrimaryScreen.WorkingArea.Size.Height / 2) - (_owner.Size.Height / 2)));
                //    _owner.Location = new Point(x, y);
                //}

                switch (icon)
                {
                    case MessageBoxIcon.Error:
                        SystemSounds.Hand.Play(); break;
                    case MessageBoxIcon.Exclamation:
                        SystemSounds.Exclamation.Play(); break;
                    case MessageBoxIcon.Question:
                        SystemSounds.Beep.Play(); break;
                    default:
                        SystemSounds.Asterisk.Play(); break;
                }

                MetroMessageBoxControl _control = new MetroMessageBoxControl();
                _control.BackColor = _owner.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.ControlBox = false;
                _control.ShowInTaskbar = false;
                //_owner.Controls.Add(_control);
                //if (_owner is IMetroForm)
                //{
                //    //if (((MetroForm)_owner).DisplayHeader)
                //    //{
                //    //    _offset += 30;
                //    //}
                //    _control.Theme = ((MetroForm)_owner).Theme;
                //    _control.Style = ((MetroForm)_owner).Style;
                //}

                _control.Properties.InputBox = (inputValue != null);

                _control.Size = new Size(_owner.Size.Width, height);
                _control.Location = new Point(_owner.Location.X, _owner.Location.Y + (_owner.Height - _control.Height) / 2);
                _control.ArrangeApperance();
                int _overlaySizes = Convert.ToInt32(Math.Floor(_control.Size.Height * 0.28));
                //_control.OverlayPanelTop.Size = new Size(_control.Size.Width, _overlaySizes - 30);
                //_control.OverlayPanelBottom.Size = new Size(_control.Size.Width, _overlaySizes);
                _control.TopMost = true;
                _control.ShowDialog();
                _control.BringToFront();
                //_control.SetFocus();

                Action<MetroMessageBoxControl> _delegate = new Action<MetroMessageBoxControl>(ModalState);
                IAsyncResult _asyncresult = _delegate.BeginInvoke(_control, null, _delegate);
                bool _cancelled = false;

                try
                {
                    while (!_asyncresult.IsCompleted)
                    { Thread.Sleep(1); Application.DoEvents(); }
                }
                catch
                {
                    _cancelled = true;

                    if (!_asyncresult.IsCompleted)
                    {
                        try { _asyncresult = null; }
                        catch { }
                    }

                    _delegate = null;
                }

                if (!_cancelled)
                {
                    _result = _control.Result;
                    inputValue = _control.InputBoxText;
                    //_owner.Controls.Remove(_control);
                    _control.Dispose(); _control = null;
                }

            }

            return _result;
        }
コード例 #4
0
 /// <summary>
 /// Modals the state.
 /// </summary>
 /// <param name="control">The control.</param>
 private static void ModalState(MetroMessageBoxControl control)
 {
     while (control.Visible)
     { }
 }
コード例 #5
0
 /// <summary>
 /// Creates a new instance of MessageBoxOverlayProperties.
 /// </summary>
 /// <param name="owner"></param>
 public MetroMessageBoxProperties(MetroMessageBoxControl owner)
 {
     _owner = owner;
 }