public void Notify(string caption, string message, Action action)
        {
            if (Form == null)
            {
                return;
            }

            var ctr = new AlertControl();
            var info = new AlertInfo(caption, message);

            var handler = new AlertClickEventHandler(
                (o, e) =>
                {
                    if (action != null)
                    {
                        action.Invoke();
                    }
                }
            );

            ctr.AlertClick += handler;

            ctr.FormClosing += (o, e) =>
            {
                ctr.AlertClick -= handler;
            };

            Form.Invoke((Action)(() =>
            {
                ctr.Show(Form, info);
            }));
        }
Example #2
0
        /// <summary>
        /// 显示消息窗
        /// </summary>
        /// <param name="state"></param>
        private static DialogResult ShowWindow(object state)
        {
            DialogResult dr = DialogResult.Cancel;

            if (!(state is object[]))
            {
                return(dr);                        //排除异常参数9
            }
            object[]      param        = state as object[];
            string        msg          = param[0] == null ? null : param[0].ToString();
            string        title        = param[1] == null ? "温馨提示" : param[1].ToString();
            MessageIcon   icon         = (MessageIcon)param[2];
            MessageButton btn          = (MessageButton)param[3];
            IWin32Window  owner        = param[4] as IWin32Window;
            bool          flow         = (bool)param[5];
            int           autoCloseSec = (int)param[6];

            ISupportLookAndFeel iLookAndFeel = owner as ISupportLookAndFeel;
            string skinName = null;

            if (iLookAndFeel != null)
            {
                UserLookAndFeel lookAndFeel = iLookAndFeel.LookAndFeel;
                skinName = lookAndFeel.UseDefaultLookAndFeel
                    ? UserLookAndFeel.Default.SkinName
                    : lookAndFeel.SkinName;
            }
            if (flow)
            {
                if (alertctrl == null)
                {
                    alertctrl = new AlertControl();
                    alertctrl.ShowPinButton                                 = true;
                    alertctrl.ShowCloseButton                               = true;
                    alertctrl.ShowToolTips                                  = true;
                    alertctrl.FormShowingEffect                             = AlertFormShowingEffect.SlideHorizontal;
                    alertctrl.FormLocation                                  = AlertFormLocation.BottomRight;
                    alertctrl.FormDisplaySpeed                              = AlertFormDisplaySpeed.Moderate;
                    alertctrl.AppearanceText.Font                           = new Font("微软雅黑", 10F, FontStyle.Regular, GraphicsUnit.Point, ((byte)(134)));
                    alertctrl.AppearanceText.Options.UseFont                = true;
                    alertctrl.AppearanceHotTrackedText.Font                 = new Font("微软雅黑", 10F, FontStyle.Regular, GraphicsUnit.Point, ((byte)(134)));
                    alertctrl.AppearanceHotTrackedText.Options.UseFont      = true;
                    alertctrl.AppearanceHotTrackedText.ForeColor            = Color.DodgerBlue;
                    alertctrl.AppearanceHotTrackedText.Options.UseForeColor = true;
                    alertctrl.AutoHeight = true;
                    alertctrl.AppearanceCaption.TextOptions.HAlignment = HorzAlignment.Center;
                    alertctrl.AppearanceCaption.TextOptions.VAlignment = VertAlignment.Bottom;
                    alertctrl.AppearanceCaption.Font = new Font("微软雅黑", 9F, FontStyle.Regular, GraphicsUnit.Point, ((byte)(134)));
                    alertctrl.AppearanceCaption.Options.UseTextOptions = true;
                }
                alertctrl.AutoFormDelay = autoCloseSec * 1000;

                if (skinName != null && skinName != alertctrl.LookAndFeel.SkinName)
                {
                    alertctrl.LookAndFeel.SetSkinStyle(skinName);
                }

                alertctrl.AlertClick  += AlertClick;
                alertctrl.FormClosing += AlertClosing;
                AlertClick             = null;
                AlertClosing           = null;
                alertctrl.Show(FormMessage.Instance, "[" + title + "]", msg + "\n\n");
                return(DialogResult.OK);
            }
            else
            {
                if (skinName != null && skinName != FormMessage.Instance.LookAndFeel.SkinName)
                {
                    FormMessage.Instance.LookAndFeel.SetSkinStyle(skinName);
                }

                if (BtnClick != null)
                {
                    FormMessage.Instance.BtnOkClick     = BtnClick;
                    FormMessage.Instance.BtnCancelClick = BtnClick;
                }
                else
                {
                    FormMessage.Instance.BtnOkClick     = BtnOkClick;
                    FormMessage.Instance.BtnCancelClick = BtnCancelClick;
                }
                BtnOkClick     = null;
                BtnCancelClick = null;
                BtnClick       = null;

                dr = FormMessage.Instance.ShowDialog(msg, title, icon, btn, owner);
                return(dr);
            }
        }
Example #3
0
        public static AlertClickEventHandler alertClick;//点击内容事件

        /// <summary>
        /// 显示消息窗
        /// </summary>
        /// <param name="state"></param>
        private static DialogResult ShowWindow(object state)
        {
            DialogResult dr = DialogResult.Cancel;

            if (!(state is object[]))
            {
                return(dr);                        //排除异常参数
            }
            object[]      param = state as object[];
            string        msg   = param[0] == null ? null : param[0].ToString();
            string        title = param[1] == null ? "温馨提示" : param[1].ToString();
            MessageIcon   icon  = (MessageIcon)param[2];
            MessageButton btn   = (MessageButton)param[3];
            IWin32Window  owner = param[4] as IWin32Window;
            bool          flow  = (bool)param[5];

            if (flow)
            {
                AlertControl alertctrl = new AlertControl();
                alertctrl.ShowPinButton                            = true;
                alertctrl.ShowCloseButton                          = true;
                alertctrl.ShowToolTips                             = true;
                alertctrl.FormShowingEffect                        = AlertFormShowingEffect.SlideHorizontal;
                alertctrl.FormLocation                             = AlertFormLocation.BottomRight;
                alertctrl.FormDisplaySpeed                         = AlertFormDisplaySpeed.Moderate;
                alertctrl.AutoFormDelay                            = 10000;
                alertctrl.AppearanceText.Font                      = new Font("微软雅黑", 10F, FontStyle.Regular, GraphicsUnit.Point, ((byte)(134)));
                alertctrl.AppearanceText.Options.UseFont           = true;
                alertctrl.AppearanceHotTrackedText.Font            = new Font("微软雅黑", 10F, FontStyle.Regular, GraphicsUnit.Point, ((byte)(134)));
                alertctrl.AppearanceHotTrackedText.Options.UseFont = true;
                alertctrl.AutoHeight = true;
                alertctrl.AppearanceCaption.TextOptions.HAlignment = HorzAlignment.Center;
                alertctrl.AppearanceCaption.TextOptions.VAlignment = VertAlignment.Bottom;
                alertctrl.AppearanceCaption.Font = new Font("微软雅黑", 9F, FontStyle.Regular, GraphicsUnit.Point, ((byte)(134)));
                alertctrl.AppearanceCaption.Options.UseTextOptions = true;
                alertctrl.Show(FormMessage.Instance, "[" + title + "]", msg + "\n\n");
                alertctrl.AlertClick += alertClick;
                alertClick            = null;
                return(DialogResult.OK);
            }
            else
            {
                if (btnClick != null)
                {
                    FormMessage.Instance.btnOKClick     = btnClick;
                    FormMessage.Instance.btnCancelClick = btnClick;
                }
                else
                {
                    FormMessage.Instance.btnOKClick     = btnOKClick;
                    FormMessage.Instance.btnCancelClick = btnCancelClick;
                }
                btnOKClick     = null;
                btnCancelClick = null;
                btnClick       = null;
                FormMessage.Instance.CrossThreadCalls(() =>
                {
                    dr = FormMessage.Instance.ShowDialog(msg, title, icon, btn, owner);
                }
                                                      );
                return(dr);
            }
        }