Пример #1
0
        public static void ShowForm(Panel ownerPnl, Control pnl)
        {
            HideMessage(ownerPnl);

            var msgPnl = new UXMessageMask()
            {
                Name = "msgPnl"
            };

            msgPnl.Left   = 0;
            msgPnl.Top    = 0;
            msgPnl.Width  = ownerPnl.Width;
            msgPnl.Height = ownerPnl.Height;
            msgPnl.Anchor = AnchorStyles.Left | AnchorStyles.Top | AnchorStyles.Right | AnchorStyles.Bottom;
            ownerPnl.Controls.Add(msgPnl);
            msgPnl.BringToFront();

            var x = (ownerPnl.Width - pnl.Width) / 2;
            var y = (ownerPnl.Height - pnl.Height) / 2;

            pnl.Location = new Point(x, y);
            msgPnl.Controls.Add(pnl);
            pnl.Disposed += (obj, args) => {
                HideMessage(ownerPnl);
            };
        }
Пример #2
0
        public static void ShowMessage(Panel ownerPnl, bool isModal, string msg, MessageBoxButtonsType btnType, MessageBoxIcon boxIcon
                                       , Action okAction = null, Action cancelAction = null, Action noAction = null)
        {
            HideMessage(ownerPnl);

            var msgPnl = new UXMessageMask()
            {
                Name = "msgPnl"
            };

            msgPnl.Left   = 0;
            msgPnl.Top    = 0;
            msgPnl.Width  = ownerPnl.Width;
            msgPnl.Height = ownerPnl.Height;
            msgPnl.Anchor = AnchorStyles.Left | AnchorStyles.Top | AnchorStyles.Right | AnchorStyles.Bottom;
            ownerPnl.Controls.Add(msgPnl);
            msgPnl.BringToFront();

            if (isModal)
            {
                var win = new UXMessageWindow()
                {
                    Message = msg,
                    MessageBoxButtonsType = btnType,
                    MessageBoxIcon        = boxIcon,
                    OKAction     = okAction,
                    CancelAction = cancelAction,
                    NoAction     = noAction,
                    Owner        = ownerPnl.FindForm()
                };
                win.FormClosed += (sender, args) => { HideMessage(ownerPnl); };
                win.ShowDialog();
            }
            else
            {
                var msgBox = new UXMessagePanel()
                {
                    Message = msg,
                    MessageBoxButtonsType = btnType,
                    MessageBoxIcon        = boxIcon,
                    OKAction     = okAction,
                    CancelAction = cancelAction,
                    NoAction     = noAction
                };
                var x = (ownerPnl.Width - msgBox.Width) / 2;
                var y = (ownerPnl.Height - msgBox.Height) / 2;
                msgBox.Location  = new Point(x, y);
                msgBox.Disposed += (obj, args) => { HideMessage(ownerPnl); };
                msgPnl.Controls.Add(msgBox);
            }
        }