Ejemplo n.º 1
0
 public static void Show(string s, string housekeeperStatements, MessageBoxButtons ok)
 {
     System.Diagnostics.Debug.WriteLine(s + housekeeperStatements + ok.ToString());
 }
Ejemplo n.º 2
0
        private List <Button> ObtenerBotones(MessageBoxButtons messageBoxButtons, Font fuente, DialogResult defaultButton)
        {
            List <Button> botones = new List <Button>();

            switch (messageBoxButtons)
            {
            case MessageBoxButtons.OK:
                botones.Add(ObtenerBoton("Aceptar", AnchorStyles.None, fuente, Ok_Click, defaultButton == DialogResult.OK));
                break;

            case MessageBoxButtons.YesNo:
                botones.Add(ObtenerBoton("Si", AnchorStyles.Right, fuente, Yes_Click, defaultButton == DialogResult.Yes));
                botones.Add(ObtenerBoton("No", AnchorStyles.Left, fuente, No_Click, defaultButton == DialogResult.No));
                break;

            case MessageBoxButtons.OKCancel:
                botones.Add(ObtenerBoton("Aceptar", AnchorStyles.Right, fuente, Ok_Click, defaultButton == DialogResult.OK));
                botones.Add(ObtenerBoton("Cancelar", AnchorStyles.Left, fuente, Cancel_Click, defaultButton == DialogResult.Cancel));
                break;

            default: throw new InvalidOperationException($"No se encuentra implementado el tipo {messageBoxButtons.ToString()}");
            }
            return(botones);
        }
Ejemplo n.º 3
0
        void SetButtonState(string[] button_texts = null)
        {
            {
                ButtonInfo info = null;

                this.m_buttonInfos = new List <ButtonInfo>();
                if (this.m_buttonDef == MessageBoxButtons.OK)
                {
                    // 按钮1不使用
                    info         = new ButtonInfo();
                    info.Visible = false;
                    this.m_buttonInfos.Add(info);

                    // 按钮2不使用
                    info         = new ButtonInfo();
                    info.Visible = false;
                    this.m_buttonInfos.Add(info);

                    // 按钮3
                    info = new ButtonInfo();
                    info.DialogResult = System.Windows.Forms.DialogResult.OK;
                    info.Text         = "确定";
                    info.Visible      = true;
                    info.Style        = "accept";
                    this.m_buttonInfos.Add(info);
                }
                else if (this.m_buttonDef == MessageBoxButtons.OKCancel)
                {
                    // 按钮1不使用
                    info         = new ButtonInfo();
                    info.Visible = false;
                    this.m_buttonInfos.Add(info);


                    // 按钮2
                    info = new ButtonInfo();
                    info.DialogResult = System.Windows.Forms.DialogResult.OK;
                    info.Text         = "确定";
                    info.Visible      = true;
                    if (this.m_defautButton == MessageBoxDefaultButton.Button1)
                    {
                        info.Style = "accept";
                    }
                    this.m_buttonInfos.Add(info);

                    // 按钮3
                    info = new ButtonInfo();
                    info.DialogResult = System.Windows.Forms.DialogResult.Cancel;
                    info.Text         = "取消";
                    info.Visible      = true;
                    if (this.m_defautButton == MessageBoxDefaultButton.Button2)
                    {
                        info.Style = "accept";
                    }
                    StringUtil.SetInList(ref info.Style, "cancel", true);
                    this.m_buttonInfos.Add(info);
                }
                else if (this.m_buttonDef == MessageBoxButtons.YesNo)
                {
                    // 按钮1不使用
                    info         = new ButtonInfo();
                    info.Visible = false;
                    this.m_buttonInfos.Add(info);


                    // 按钮2
                    info = new ButtonInfo();
                    info.DialogResult = System.Windows.Forms.DialogResult.Yes;
                    info.Text         = "是";
                    info.Visible      = true;
                    if (this.m_defautButton == MessageBoxDefaultButton.Button1)
                    {
                        info.Style = "accept";
                    }
                    this.m_buttonInfos.Add(info);

                    // 按钮3
                    info = new ButtonInfo();
                    info.DialogResult = System.Windows.Forms.DialogResult.No;
                    info.Text         = "否";
                    info.Visible      = true;
                    if (this.m_defautButton == MessageBoxDefaultButton.Button2)
                    {
                        info.Style = "accept";
                    }
                    StringUtil.SetInList(ref info.Style, "cancel", true);
                    this.m_buttonInfos.Add(info);
                }
                else if (this.m_buttonDef == MessageBoxButtons.YesNoCancel)
                {
                    // 按钮1
                    info = new ButtonInfo();
                    info.DialogResult = System.Windows.Forms.DialogResult.Yes;
                    info.Text         = "是";
                    info.Visible      = true;
                    if (this.m_defautButton == MessageBoxDefaultButton.Button1)
                    {
                        info.Style = "accept";
                    }
                    this.m_buttonInfos.Add(info);

                    // 按钮2
                    info = new ButtonInfo();
                    info.DialogResult = System.Windows.Forms.DialogResult.No;
                    info.Text         = "否";
                    info.Visible      = true;
                    if (this.m_defautButton == MessageBoxDefaultButton.Button2)
                    {
                        info.Style = "accept";
                    }
                    StringUtil.SetInList(ref info.Style, "cancel", true);
                    this.m_buttonInfos.Add(info);

                    // 按钮3
                    info = new ButtonInfo();
                    info.DialogResult = System.Windows.Forms.DialogResult.Cancel;
                    info.Text         = "取消";
                    info.Visible      = true;
                    if (this.m_defautButton == MessageBoxDefaultButton.Button3)
                    {
                        info.Style = "accept";
                    }
                    this.m_buttonInfos.Add(info);
                }
                else
                {
                    throw new Exception("不支持的 " + m_buttonDef.ToString());
                }

                // 兑现到按钮上
                if (this.m_buttonInfos.Count > 0)
                {
                    info = this.m_buttonInfos[0];
                    this.button_1.Visible = info.Visible;
                    if (info.Visible == true)
                    {
                        this.button_1.Text = info.Text;
                        if (StringUtil.IsInList("accept", info.Style) == true)
                        {
                            this.AcceptButton = this.button_1;
                        }
                        if (StringUtil.IsInList("cancel", info.Style) == true)
                        {
                            this.CancelButton = this.button_1;
                        }
                    }
                }

                if (this.m_buttonInfos.Count > 1)
                {
                    info = this.m_buttonInfos[1];
                    this.button_2.Visible = info.Visible;
                    if (info.Visible == true)
                    {
                        this.button_2.Text = info.Text;
                        if (StringUtil.IsInList("accept", info.Style) == true)
                        {
                            this.AcceptButton = this.button_2;
                        }
                        if (StringUtil.IsInList("cancel", info.Style) == true)
                        {
                            this.CancelButton = this.button_2;
                        }
                    }
                }

                if (this.m_buttonInfos.Count > 2)
                {
                    info = this.m_buttonInfos[2];
                    this.button_3.Visible = info.Visible;
                    if (info.Visible == true)
                    {
                        this.button_3.Text = info.Text;
                        if (StringUtil.IsInList("accept", info.Style) == true)
                        {
                            this.AcceptButton = this.button_3;
                        }
                        if (StringUtil.IsInList("cancel", info.Style) == true)
                        {
                            this.CancelButton = this.button_3;
                        }
                    }
                }
            }


            if (button_texts != null)
            {
                int           i     = 0;
                List <string> texts = new List <string>();
                foreach (ButtonInfo info in this.m_buttonInfos)
                {
                    if (i >= button_texts.Length)
                    {
                        break;
                    }
                    if (info.Visible == false)
                    {
                        texts.Add(null);
                        continue;
                    }
                    texts.Add(button_texts[i]);
                    i++;
                }

                if (texts.Count > 0)
                {
                    string strText = texts[0];

                    if (strText != null)
                    {
                        this.button_1.Text = strText;
                    }
                }

                if (texts.Count > 1)
                {
                    string strText = texts[1];

                    if (strText != null)
                    {
                        this.button_2.Text = strText;
                    }
                }

                if (texts.Count > 2)
                {
                    string strText = texts[2];

                    if (strText != null)
                    {
                        this.button_3.Text = strText;
                    }
                }
            }
#if NO
            if (button_texts != null)
            {
                if (button_texts.Length > 0)
                {
                    string strText = button_texts[0];

                    if (strText != null)
                    {
                        this.button_1.Text = strText;
                    }
                }

                if (button_texts.Length > 1)
                {
                    string strText = button_texts[1];

                    if (strText != null)
                    {
                        this.button_2.Text = strText;
                    }
                }

                if (button_texts.Length > 2)
                {
                    string strText = button_texts[2];

                    if (strText != null)
                    {
                        this.button_3.Text = strText;
                    }
                }
            }
#endif

#if NO
            // //
            if (this.m_buttonInfos.Count > 0)
            {
                info = this.m_buttonInfos[0];
                if (info.Visible == true)
                {
                    if (StringUtil.IsInList("accept", info.Style) == true)
                    {
                        this.AcceptButton = this.button_1;
                    }
                    if (StringUtil.IsInList("cancel", info.Style) == true)
                    {
                        this.CancelButton = this.button_1;
                    }
                }
            }

            if (this.m_buttonInfos.Count > 1)
            {
                info = this.m_buttonInfos[1];
                if (info.Visible == true)
                {
                    if (StringUtil.IsInList("accept", info.Style) == true)
                    {
                        this.AcceptButton = this.button_2;
                    }
                    if (StringUtil.IsInList("cancel", info.Style) == true)
                    {
                        this.CancelButton = this.button_2;
                    }
                }
            }

            if (this.m_buttonInfos.Count > 2)
            {
                info = this.m_buttonInfos[2];
                if (info.Visible == true)
                {
                    if (StringUtil.IsInList("accept", info.Style) == true)
                    {
                        this.AcceptButton = this.button_3;
                    }
                    if (StringUtil.IsInList("cancel", info.Style) == true)
                    {
                        this.CancelButton = this.button_3;
                    }
                }
            }
#endif
        }
 /// <summary>
 /// Parses the specified MessageBoxButtons value.
 /// </summary>
 /// <param name="value">The value.</param>
 /// <returns>The converted value</returns>
 internal static InformationBoxButtons Parse(MessageBoxButtons value)
 {
     return((InformationBoxButtons)Enum.Parse(typeof(InformationBoxButtons), value.ToString()));
 }
Ejemplo n.º 5
0
        private yMessageBox(
            Control parent         = null,
            string msg             = "",
            string title           = "MessageBox",
            MessageBoxButtons btns = MessageBoxButtons.OK,
            MessageBoxIcon icon    = MessageBoxIcon.None)
        {
            InitializeComponent();

            richBoxMessage.BorderStyle = BorderStyle.None;

            this.Text = title;
            this.richBoxMessage.Text = msg;
            //this.TopLevel = false;
            //this.Parent = parent;
            this.StartPosition = FormStartPosition.CenterParent;

            _btnType = btns;
            if (btns == MessageBoxButtons.OK)
            {
                btn1.Text    = "OK";
                btn2.Visible = false;
                btn2.Enabled = false;
            }
            else if (btns == MessageBoxButtons.YesNo)
            {
                btn1.Text    = "No";
                btn2.Text    = "Yes";
                btn1.Visible = btn2.Visible = true;
                btn1.Enabled = btn2.Enabled = true;
            }
            else if (btns == MessageBoxButtons.OKCancel)
            {
                btn1.Text    = "Cancle";
                btn2.Text    = "OK";
                btn1.Visible = btn2.Visible = true;
                btn1.Enabled = btn2.Enabled = true;
            }
            else
            {
                throw new ArgumentException("Invalid MessageBoxButtons \"" + btns.ToString() + "\"");
            }

            picBox.SizeMode = PictureBoxSizeMode.StretchImage;

            if (icon == MessageBoxIcon.Error)
            {
                picBox.Image = Properties.Resources.error;
            }
            else if (icon == MessageBoxIcon.Question)
            {
                picBox.Image = Properties.Resources.confirm;
            }
            else if (icon == MessageBoxIcon.Information)
            {
                picBox.Image = Properties.Resources.info;
            }
            else
            {
                picBox.Visible = false;
            }
        }
Ejemplo n.º 6
0
        private static void ShowMessageBoxResult(MessageBoxButtons buttons)
        {
            var result = MessageBox.Show(buttons.ToString(), "", buttons);

            MessageBox.Show(result.ToString());
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Sets
        /// </summary>
        /// <param name="buttons"></param>
        /// <param name="bOkDefault">if true the OK button will be the default button</param>
        public void SetupForButtons(MessageBoxButtons buttons, Color buttonColor, bool bOkDefault)
        {
            switch (buttons)
            {
            case MessageBoxButtons.OK:
            {
                this.AcceptButton = bOk;
                bOk = setupButton(bOk, buttonColor, DockStyle.Right);
            }
            break;

            case MessageBoxButtons.OKCancel:
            {
                bOk     = setupButton(bOk, buttonColor, DockStyle.Left);
                bCancel = setupButton(bCancel, buttonColor, DockStyle.Right);
                bCancel.SendToBack();                 // to make it align to the right

                // manually ensure that bOK is spaced far enough away from bCancel
                bOk.Left   = bCancel.Left - 5;              // -(bOk.Width);
                bOk.Height = bCancel.Height;
                bOk.Top    = bCancel.Top;

                bCancel.TabIndex  = 0;
                bOk.TabIndex      = 1;
                this.AcceptButton = bCancel;
            }
            break;

            case MessageBoxButtons.YesNo:
            {
                setupYesNo(buttonColor);
            } break;

            case MessageBoxButtons.YesNoCancel:
            {
                setupYesNoCancel(buttonColor);
            } break;

            case MessageBoxButtons.RetryCancel:
            {
                setupYesNo(buttonColor);
                bOk.Text         = "Retry";
                bOk.DialogResult = DialogResult.Retry;
                bNo.Text         = "Cancel";
                bNo.DialogResult = DialogResult.Cancel;
            } break;

            case MessageBoxButtons.AbortRetryIgnore:
            {
                setupYesNoCancel(buttonColor);
                bOk.Text         = "Abort";
                bOk.DialogResult = DialogResult.Abort;

                bNo.Text         = "Retry";
                bNo.DialogResult = DialogResult.Retry;

                bCancel.Text         = "Ignore";
                bCancel.DialogResult = DialogResult.Cancel;
            } break;

            default: MessageBox.Show(buttons.ToString() + " is unhandled in NewMessage"); break;
            }

            if (bOkDefault == true)
            {
                this.AcceptButton = bOk;
            }
        }
Ejemplo n.º 8
0
        private string GenerateCode()
        {
            StringBuilder stringBuilder = new StringBuilder();

            if (showMessageBox)
            {
                stringBuilder.Append(Constants.CodeGeneratorMsgBoxInst);
                if (setParent)
                {
                    stringBuilder.Append(Constants.CodeGeneratorThis);
                    stringBuilder.Append(Constants.CodeGeneratorCommaAndSpace);
                }
                stringBuilder.Append(string.IsNullOrEmpty(text) ? Constants.CodeGeneratorNull : ArgumentParser.EscapeArgument(text));
                if (!string.IsNullOrEmpty(caption) || boxButtons > 0 || boxIcon > 0 || boxDefaultButton > 0)
                {
                    stringBuilder.Append(Constants.CodeGeneratorCommaAndSpace);
                    stringBuilder.Append(string.IsNullOrEmpty(caption) ? Constants.CodeGeneratorNull : ArgumentParser.EscapeArgument(caption));
                }
                if (boxButtons > 0 || boxIcon > 0 || formDefaultButton > 0)
                {
                    stringBuilder.Append(Constants.CodeGeneratorCommaAndSpace);
                    stringBuilder.Append(string.Join(".", new string[] { typeof(MessageBoxButtons).Name, boxButtons.ToString() }));
                }
                if (boxIcon > 0 || formDefaultButton > 0)
                {
                    stringBuilder.Append(Constants.CodeGeneratorCommaAndSpace);
                    stringBuilder.Append(string.Join(".", new string[] { typeof(MessageBoxIcon).Name, boxIcon.ToString() }));
                }
                if (boxDefaultButton > 0)
                {
                    stringBuilder.Append(Constants.CodeGeneratorCommaAndSpace);
                    stringBuilder.Append(string.Join(".", new string[] { typeof(MessageBoxDefaultButton).Name, boxDefaultButton.ToString() }));
                }
                stringBuilder.Append(Constants.CodeGeneratorEndBracketAndSemicolon);
            }
            else
            {
                stringBuilder.Append(Constants.CodeGeneratorMsgFormInst);
                if (setParent)
                {
                    stringBuilder.Append(Constants.CodeGeneratorThis);
                    stringBuilder.Append(Constants.CodeGeneratorCommaAndSpace);
                }
                stringBuilder.Append(string.IsNullOrEmpty(text) ? Constants.CodeGeneratorNull : ArgumentParser.EscapeArgument(text));
                if (!string.IsNullOrEmpty(caption) || formButtons > 0 || formBoxIcon > 0 || formDefaultButton > 0 || centerScreen || showHelpButton || maximumWidth > 0 && maximumWidth != MessageForm.defaultWidth || noWrap)
                {
                    stringBuilder.Append(Constants.CodeGeneratorCommaAndSpace);
                    stringBuilder.Append(string.IsNullOrEmpty(caption) ? Constants.CodeGeneratorNull : ArgumentParser.EscapeArgument(caption));
                }
                if (formButtons > 0 || formBoxIcon > 0 || formDefaultButton > 0 || centerScreen || showHelpButton || maximumWidth > 0 && maximumWidth != MessageForm.defaultWidth || noWrap)
                {
                    stringBuilder.Append(Constants.CodeGeneratorCommaAndSpace);
                    stringBuilder.Append(string.Join(".", new string[] { typeof(MessageForm.Buttons).Namespace, typeof(MessageForm.Buttons).Name, formButtons.ToString() }));
                }
                if (formBoxIcon > 0 || formDefaultButton > 0 || centerScreen || showHelpButton || maximumWidth > 0 && maximumWidth != MessageForm.defaultWidth || noWrap)
                {
                    stringBuilder.Append(Constants.CodeGeneratorCommaAndSpace);
                    stringBuilder.Append(string.Join(".", new string[] { typeof(MessageForm.BoxIcon).Namespace, typeof(MessageForm.BoxIcon).Name, formBoxIcon.ToString() }));
                }
                if (formDefaultButton > 0 || centerScreen || showHelpButton || maximumWidth > 0 && maximumWidth != MessageForm.defaultWidth || noWrap)
                {
                    stringBuilder.Append(Constants.CodeGeneratorCommaAndSpace);
                    stringBuilder.Append(string.Join(".", new string[] { typeof(MessageForm.DefaultButton).Namespace, typeof(MessageForm.DefaultButton).Name, formDefaultButton.ToString() }));
                }
                if (centerScreen || showHelpButton || maximumWidth > 0 && maximumWidth != MessageForm.defaultWidth || noWrap)
                {
                    stringBuilder.Append(Constants.CodeGeneratorCommaAndSpace);
                    stringBuilder.Append(centerScreen.ToString().ToLowerInvariant());
                }
                if (showHelpButton || maximumWidth > 0 && maximumWidth != MessageForm.defaultWidth || noWrap)
                {
                    stringBuilder.Append(Constants.CodeGeneratorCommaAndSpace);
                    stringBuilder.Append(showHelpButton.ToString().ToLowerInvariant());
                }
                if (maximumWidth > 0 && maximumWidth != MessageForm.defaultWidth || noWrap)
                {
                    stringBuilder.Append(Constants.CodeGeneratorCommaAndSpace);
                    stringBuilder.Append(maximumWidth > 0 && maximumWidth != MessageForm.defaultWidth ? maximumWidth.ToString() : 0.ToString());
                }
                if (noWrap)
                {
                    stringBuilder.Append(Constants.CodeGeneratorCommaAndSpace);
                    stringBuilder.Append(noWrap.ToString().ToLowerInvariant());
                }
                stringBuilder.AppendLine(Constants.CodeGeneratorEndBracketAndSemicolon);
                stringBuilder.Append(Constants.CodeGeneratorMsgFormShowDlg);
                if (setParent)
                {
                    stringBuilder.Append(Constants.CodeGeneratorThis);
                }
                stringBuilder.Append(Constants.CodeGeneratorEndBracketAndSemicolon);
            }
            return(stringBuilder.ToString());
        }