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>
        /// <param name="height" optional=211></param>
        /// <returns></returns>
        public static DialogResult Show(IWin32Window owner, String message, String title, MessageBoxButtons buttons, MessageBoxIcon icon, MessageBoxDefaultButton defaultbutton, int height = 211)
        {
            DialogResult _result = DialogResult.None;

            if (owner != null)
            {
                Form _owner = (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 = Color.White;

                _control.Properties.Buttons       = buttons;
                _control.Properties.DefaultButton = defaultbutton;
                _control.Properties.Icon          = icon;
                _control.Properties.Message       = message;
                _control.Properties.Title         = title;
                _control.ControlBox    = false;
                _control.ShowInTaskbar = false;

                _control.ArrangeApperance();

                _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);
        }
        /// <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>
        /// <returns></returns>
        public static DialogResult Show(IWin32Window owner, String message, String title, MessageBoxButtons buttons, MessageBoxIcon icon, MessageBoxDefaultButton defaultbutton, int height = 211)
        {
            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.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;
        }
Esempio n. 3
0
        /*
         * private static MetroForm DummyForm()
         * {
         *  MetroForm form = new MetroForm();
         *  form.Size = new Size(550, 230);
         *  form.StartPosition = FormStartPosition.CenterScreen;
         *  form.SizeGripStyle = SizeGripStyle.Hide;
         *  form.ShowIcon = false;
         *  form.ShadowType = MetroFormShadowType.AeroShadow;
         *  form.MinimizeBox = form.MaximizeBox = false;
         *  form.ControlBox = form.DisplayHeader = false;
         *  form.Padding = new Padding(0, 0, 0, 0);
         *  form.AutoSize = true;
         *
         *  return form;
         * }
         */

        /// <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;

            //bool freeowner = false;
            if (owner == null)
            {
                //freeowner = true;
                //owner = DummyForm();
                //((Form)owner).Show();
            }

            //if (owner != null)
            {
                Form _owner = (Form)owner;

                //if (_owner.WindowState == FormWindowState.Minimized)
                //_owner.WindowState = FormWindowState.Normal;

                //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.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;


                //if (freeowner)
                //_control.Dock = DockStyle.Fill;

                //_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.ArrangeApperance();

                int lt = message.TrimEnd('\r').Split(new char[] { '\r' }).Length * 23;

                if (owner != null && _owner.WindowState != FormWindowState.Minimized && _owner.Visible)
                {
                    _control.Size     = new Size(_owner.Size.Width, Math.Min(_owner.Size.Height, Math.Max(lt, _control.Height)));
                    _control.Location = new Point(_owner.Location.X, _owner.Location.Y + (_owner.Height - _control.Height) / 2);
                    //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();
                }
                else
                {
                    _control.ShowInTaskbar = true;
                    _control.StartPosition = FormStartPosition.Manual;
                    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 = new Point(x, y);
                    _control.Size     = new Size(_control.Size.Width,
                                                 Math.Min(Screen.PrimaryScreen.WorkingArea.Size.Height, Math.Max(_control.Size.Height, lt)));
                    //_control.Show();

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

                bool _cancelled = false;

                /*
                 * Action<MetroMessageBoxControl> _delegate = new Action<MetroMessageBoxControl>(ModalState);
                 * IAsyncResult _asyncresult = _delegate.BeginInvoke(_control, null, _delegate);
                 *
                 * 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;
                }
            }
            //if (freeowner)
            //((Form)owner).Dispose();

            return(_result);
        }
        public static DialogResult Show(IWin32Window owner, string message, string title, MessageBoxButtons buttons, MessageBoxIcon icon, MessageBoxDefaultButton defaultbutton, int height)
        {
            DialogResult result = DialogResult.None;

            if (owner != null)
            {
                Form           form           = (!(owner is Form) ? ((UserControl)owner).ParentForm : (Form)owner);
                MessageBoxIcon messageBoxIcon = icon;
                if (messageBoxIcon == MessageBoxIcon.Hand)
                {
                    SystemSounds.Hand.Play();
                }
                else if (messageBoxIcon == MessageBoxIcon.Question)
                {
                    SystemSounds.Beep.Play();
                }
                else if (messageBoxIcon == MessageBoxIcon.Exclamation)
                {
                    SystemSounds.Exclamation.Play();
                }
                else
                {
                    SystemSounds.Asterisk.Play();
                }
                MetroMessageBoxControl metroMessageBoxControl = new MetroMessageBoxControl()
                {
                    BackColor = form.BackColor
                };
                metroMessageBoxControl.Properties.Buttons       = buttons;
                metroMessageBoxControl.Properties.DefaultButton = defaultbutton;
                metroMessageBoxControl.Properties.Icon          = icon;
                metroMessageBoxControl.Properties.Message       = message;
                metroMessageBoxControl.Properties.Title         = title;
                metroMessageBoxControl.Padding       = new Padding(0, 0, 0, 0);
                metroMessageBoxControl.ControlBox    = false;
                metroMessageBoxControl.ShowInTaskbar = false;
                metroMessageBoxControl.TopMost       = true;
                metroMessageBoxControl.Size          = new Size(form.Size.Width, height);
                int   x        = form.Location.X;
                Point location = form.Location;
                metroMessageBoxControl.Location = new Point(x, location.Y + (form.Height - metroMessageBoxControl.Height) / 2);
                metroMessageBoxControl.ArrangeApperance();
                Size size = metroMessageBoxControl.Size;
                Convert.ToInt32(Math.Floor((double)size.Height * 0.28));
                metroMessageBoxControl.ShowDialog();
                metroMessageBoxControl.BringToFront();
                metroMessageBoxControl.SetDefaultButton();
                Action <MetroMessageBoxControl> action = new Action <MetroMessageBoxControl>(MetroMessageBox.ModalState);
                IAsyncResult asyncResult = action.BeginInvoke(metroMessageBoxControl, null, action);
                bool         flag        = false;
                try
                {
                    while (!asyncResult.IsCompleted)
                    {
                        Thread.Sleep(1);
                        Application.DoEvents();
                    }
                }
                catch
                {
                    flag = true;
                    if (!asyncResult.IsCompleted)
                    {
                        try
                        {
                            asyncResult = null;
                        }
                        catch
                        {
                        }
                    }
                    action = null;
                }
                if (!flag)
                {
                    result = metroMessageBoxControl.Result;
                    metroMessageBoxControl.Dispose();
                    metroMessageBoxControl = null;
                }
            }
            return(result);
        }
Esempio n. 5
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;

            if (owner != null)
            {
                Form _owner = (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);
                }

                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.Size     = new Size(_owner.Size.Width, _control.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();

                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;
                }

                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);
        }
Esempio n. 6
0
        public static DialogResult Show(IWin32Window owner, String message, String title = "Title",
                                        MessageBoxButtons buttons = MessageBoxButtons.OK, MessageBoxIcon icon = MessageBoxIcon.Information,
                                        int color = 0, MessageBoxDefaultButton defaultbutton = MessageBoxDefaultButton.Button2, int height = 211)
        {
            DialogResult _result = DialogResult.None;

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

                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
                {
                    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;
                _control.FormBorderStyle = FormBorderStyle.FixedDialog;
                _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(color);
                int _overlaySizes = Convert.ToInt32(Math.Floor(_control.Size.Height * 0.28));

                _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);
        }