Exemplo n.º 1
0
        /// <summary>
        /// 显示一个消息框。
        /// </summary>
        /// <param name="owner">控件拥有者。</param>
        /// <param name="parameters">设置参数。</param>
        /// <returns>返回窗体的操作结果。</returns>
        public static DialogResult ShowMsg(this Control owner, MessageBoxParameters parameters)
        {
            if (owner == null)
            {
                owner = Form.ActiveForm;
            }
            if (owner != null && owner.InvokeRequired)
            {
                return((DialogResult)owner.Invoke(new Func <Control, MessageBoxParameters, DialogResult>(ShowMsg), owner, parameters));
            }
            else
            {
                if (ShowingMsg != null)
                {
                    var e = new ShowingMsgEventArgs(owner, parameters);
                    ShowingMsg(owner, e);
                    if (e.Result != DialogResult.OK)
                    {
                        return(e.Result);
                    }
                }
                if (owner == null)
                {
                    var f = new MessageBoxForm(owner, parameters);
                    var r = f.ShowDialog();
                    parameters.CheckedResult = f.CheckedResult;
                    return(r);
                }
                else
                {
                    var ownerForm = owner.FindForm();

                    ownerForm.Activate();
                    var f = new MessageBoxForm(owner, parameters);
                    var r = f.ShowDialog(owner);
                    ownerForm.Activate();
                    parameters.CheckedResult = f.CheckedResult;
                    return(r);
                }
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// 显示一个消息框。
        /// </summary>
        /// <param name="owner">控件拥有者。</param>
        /// <param name="parameters">设置参数。</param>
        /// <returns>返回窗体的操作结果。</returns>
        public static DialogResult ShowMsg(this Control owner, MessageBoxParameters parameters)
        {
            if (owner == null)
                owner = Form.ActiveForm;
            if (owner != null && owner.InvokeRequired)
            {
                return (DialogResult)owner.Invoke(new Func<Control, MessageBoxParameters, DialogResult>(ShowMsg), owner, parameters);
            }
            else
            {
                if (ShowingMsg != null)
                {
                    var e = new ShowingMsgEventArgs(owner, parameters);
                    ShowingMsg(owner, e);
                    if (e.Result != DialogResult.OK)
                        return e.Result;
                }
                if (owner == null)
                {
                    var f = new MessageBoxForm(owner, parameters);
                    var r = f.ShowDialog();
                    parameters.CheckedResult = f.CheckedResult;
                    return r;
                }
                else
                {
                    var ownerForm = owner.FindForm();

                    ownerForm.Activate();
                    var f = new MessageBoxForm(owner, parameters);
                    var r = f.ShowDialog(owner);
                    ownerForm.Activate();
                    parameters.CheckedResult = f.CheckedResult;
                    return r;
                }
            }
        }