Exemplo n.º 1
0
        public static DialogResult Show(Form parent, MessageBoxModel pMessageBoxModel)
        {
            using (frm_MessageBox frm = new frm_MessageBox(pMessageBoxModel))
            {
                if (parent == null || parent.IsDisposed)
                {
                    frm.StartPosition = FormStartPosition.CenterScreen;
                    if (pMessageBoxModel.FormWidth != 0)
                    {
                        frm.Width = pMessageBoxModel.FormWidth;
                    }
                    if (pMessageBoxModel.FormHeight != 0)
                    {
                        frm.Height = pMessageBoxModel.FormHeight;
                    }

                    return(frm.ShowDialog());
                }
                else
                {
                    frm.StartPosition = FormStartPosition.CenterParent;
                    if (pMessageBoxModel.FormWidth != 0)
                    {
                        frm.Width = pMessageBoxModel.FormWidth;
                    }
                    if (pMessageBoxModel.FormHeight != 0)
                    {
                        frm.Height = pMessageBoxModel.FormHeight;
                    }

                    return(frm.ShowDialog(parent));
                }
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// 显示具有指定文本、标题、按钮、图标和默认按钮的消息框
        /// </summary>
        /// <param name="text">文本</param>
        /// <param name="caption">标题</param>
        /// <param name="buttons">按钮</param>
        /// <param name="icon">图标</param>
        /// <param name="defaultButton">默认按钮</param>
        /// <returns>System.Windows.Forms.DialogResult 值之一</returns>
        public static DialogResult Show(string text, MessageBoxButtons buttons, MessageBoxIcon icon, MessageBoxDefaultButton defaultButton, Form parent, int pFormWidth = 0, int pFormHeight = 0)
        {
            using (frm_MessageBox frm = new frm_MessageBox(text, caption, buttons, icon, defaultButton))
            {
                if (parent == null || parent.IsDisposed)
                {
                    frm.StartPosition = FormStartPosition.CenterScreen;
                    if (pFormWidth != 0)
                    {
                        frm.Width = pFormWidth;
                    }
                    if (pFormHeight != 0)
                    {
                        frm.Height = pFormHeight;
                    }

                    return(frm.ShowDialog());
                }
                else
                {
                    frm.StartPosition = FormStartPosition.CenterParent;
                    if (pFormWidth != 0)
                    {
                        frm.Width = pFormWidth;
                    }
                    if (pFormHeight != 0)
                    {
                        frm.Height = pFormHeight;
                    }

                    return(frm.ShowDialog(parent));
                }
            }
        }