/// <summary>
        /// Displays a message box with the specified text, caption, buttons, icon and default button.
        /// The text can be copied.
        /// </summary>
        /// <param name="message">The text to display in the message box.  This text can be copied.</param>
        /// <param name="caption">The text to display in the title bar of the message box.</param>
        /// <param name="buttons">One of the <see cref="CopyableMessageBoxButtons"/> values that specifies which buttons to display in the message box.
        /// If not specified, <see cref="CopyableMessageBoxButtons.OK"/> is used.</param>
        /// <param name="icon">One of the <see cref="CopyableMessageBoxIcon"/> values that specifies which icon to display in the message box.
        /// If not specified, <see cref="CopyableMessageBoxIcon.None"/> is used.</param>
        /// <param name="defBtn">The zero-based index of the default button.
        /// If not specified, <c>0</c> is used.</param>
        /// <returns>The zero-based index of the button pressed.</returns>
        public static int Show(string message, string caption,
                               CopyableMessageBoxButtons buttons = CopyableMessageBoxButtons.OK,
                               CopyableMessageBoxIcon icon       = CopyableMessageBoxIcon.None,
                               int defBtn = 0)
        {
            int cncBtn = enumToCncBtn(buttons);

            return(Show(message, caption, icon, enumToList(buttons), defBtn, cncBtn));
        }
        internal CopyableMessageBoxInternal(string message, string caption, CopyableMessageBoxIcon icon, IList<string> buttons, int defBtn, int cncBtn)
            : this()
        {
            if (buttons.Count < 1)
                throw new ArgumentLengthException("At least one button text must be supplied");

            this.tbMessage.Lines = (message + "\n").Split('\n');
            this.Text = caption;
            enumToGlyph(icon, lbIcon);
            CreateButtons(buttons, defBtn, cncBtn);

            this.DialogResult = DialogResult.OK;
        }
        internal CopyableMessageBoxInternal(string message, string caption, CopyableMessageBoxIcon icon, IList <string> buttons, int defBtn, int cncBtn)
            : this()
        {
            if (buttons.Count < 1)
            {
                throw new ArgumentLengthException("At least one button text must be supplied");
            }

            this.tbMessage.Lines = (message + "\n").Split('\n');
            this.Text            = caption;
            enumToGlyph(icon, lbIcon);
            CreateButtons(buttons, defBtn, cncBtn);

            this.DialogResult = DialogResult.OK;
        }
        private void enumToGlyph(CopyableMessageBoxIcon icon, Label lb)
        {
            switch (icon)
            {
            case CopyableMessageBoxIcon.Information:
                lb.Visible = true; lb.Text = "i"; lb.ForeColor = Color.Blue; lb.BackColor = Color.FromArgb(240, 240, 255); lb.Font = new Font(lb.Font, FontStyle.Italic); break;

            case CopyableMessageBoxIcon.Question:
                lb.Visible = true; lb.Text = "?"; lb.ForeColor = Color.Green; lb.BackColor = Color.FromArgb(240, 255, 240); lb.Font = new Font(lb.Font, FontStyle.Regular); break;

            case CopyableMessageBoxIcon.Warning:
                lb.Visible = true; lb.Text = "!"; lb.ForeColor = Color.Black; lb.BackColor = Color.Yellow; lb.Font = new Font(lb.Font, FontStyle.Bold); break;

            case CopyableMessageBoxIcon.Error:
                lb.Visible = true; lb.Text = "X"; lb.ForeColor = Color.White; lb.BackColor = Color.Red; lb.Font = new Font(lb.Font, FontStyle.Bold); break;

            case CopyableMessageBoxIcon.None:
            default:
                lb.Visible = false; break;
            }
        }
        /// <summary>
        /// Displays a message box with the specified text, caption, icon, buttons, default button and cancel button.
        /// The text can be copied.
        /// </summary>
        /// <param name="owner">An implementation of <see cref="System.Windows.Forms.IWin32Window"/> that will own the modal dialog box.</param>
        /// <param name="message">The text to display in the message box.  This text can be copied.</param>
        /// <param name="caption">The text to display in the title bar of the message box.</param>
        /// <param name="icon">One of the <see cref="CopyableMessageBoxIcon"/> values that specifies which icon to display in the message box.</param>
        /// <param name="buttons">A <see cref="IList{T}"/> (where <c>T</c> is <see cref="string"/>) to display as buttons in the message box.</param>
        /// <param name="defBtn">The zero-based index of the default button.</param>
        /// <param name="cncBtn">The zero-based index of the cancel button.</param>
        /// <returns>The zero-based index of the button pressed.</returns>
        public static int Show(IWin32Window owner, string message, string caption, CopyableMessageBoxIcon icon, IList <string> buttons, int defBtn, int cncBtn)
        {
            CopyableMessageBoxInternal cmb = new CopyableMessageBoxInternal(message, caption, icon, buttons, defBtn, cncBtn);

            DialogResult dr;

            if (owner != null)
            {
                cmb.Icon = ((Form)owner).Icon; dr = cmb.ShowDialog(owner);
            }
            else
            {
                dr = cmb.ShowDialog();
            }

            if (dr == DialogResult.Cancel)
            {
                return(cncBtn);
            }
            return((cmb.theButton != null) ? buttons.IndexOf(cmb.theButton.Text) : -1);
        }
 private void enumToGlyph(CopyableMessageBoxIcon icon, Label lb)
 {
     switch (icon)
     {
         case CopyableMessageBoxIcon.Information:
             lb.Visible = true; lb.Text = "i"; lb.ForeColor = Color.Blue; lb.BackColor = Color.FromArgb(240, 240, 255); lb.Font = new Font(lb.Font, FontStyle.Italic); break;
         case CopyableMessageBoxIcon.Question:
             lb.Visible = true; lb.Text = "?"; lb.ForeColor = Color.Green; lb.BackColor = Color.FromArgb(240, 255, 240); lb.Font = new Font(lb.Font, FontStyle.Regular); break;
         case CopyableMessageBoxIcon.Warning:
             lb.Visible = true; lb.Text = "!"; lb.ForeColor = Color.Black; lb.BackColor = Color.Yellow; lb.Font = new Font(lb.Font, FontStyle.Bold); break;
         case CopyableMessageBoxIcon.Error:
             lb.Visible = true; lb.Text = "X"; lb.ForeColor = Color.White; lb.BackColor = Color.Red; lb.Font = new Font(lb.Font, FontStyle.Bold); break;
         case CopyableMessageBoxIcon.None:
         default:
             lb.Visible = false; break;
     }
 }
Exemple #7
0
        /// <summary>
        /// Displays a message box with the specified text, caption, icon, buttons, default button and cancel button.
        /// The text can be copied.
        /// </summary>
        /// <param name="owner">An implementation of <see cref="System.Windows.Forms.IWin32Window"/> that will own the modal dialog box.</param>
        /// <param name="message">The text to display in the message box.  This text can be copied.</param>
        /// <param name="caption">The text to display in the title bar of the message box.</param>
        /// <param name="icon">One of the <see cref="CopyableMessageBoxIcon"/> values that specifies which icon to display in the message box.</param>
        /// <param name="buttons">A <see cref="IList{T}"/> (where <c>T</c> is <see cref="string"/>) to display as buttons in the message box.</param>
        /// <param name="defBtn">The zero-based index of the default button.</param>
        /// <param name="cncBtn">The zero-based index of the cancel button.</param>
        /// <returns>The zero-based index of the button pressed.</returns>
        public static int Show(IWin32Window owner, string message, string caption, CopyableMessageBoxIcon icon, IList<string> buttons, int defBtn, int cncBtn)
        {
            CopyableMessageBoxInternal cmb = new CopyableMessageBoxInternal(message, caption, icon, buttons, defBtn, cncBtn);

            DialogResult dr;
            if (owner != null) { cmb.Icon = ((Form)owner).Icon; dr = cmb.ShowDialog(owner); } else { dr = cmb.ShowDialog(); }

            if (dr == DialogResult.Cancel) return cncBtn;
            return (cmb.theButton != null) ? buttons.IndexOf(cmb.theButton.Text) : -1;
        }
Exemple #8
0
 /// <summary>
 /// Displays a message box with the specified text, caption, icon, buttons, default button and cancel button.
 /// The text can be copied.
 /// </summary>
 /// <param name="message">The text to display in the message box.  This text can be copied.</param>
 /// <param name="caption">The text to display in the title bar of the message box.</param>
 /// <param name="icon">One of the <see cref="CopyableMessageBoxIcon"/> values that specifies which icon to display in the message box.</param>
 /// <param name="buttons">A <see cref="IList{T}"/> (where <c>T</c> is <see cref="string"/>) to display as buttons in the message box.</param>
 /// <param name="defBtn">The zero-based index of the default button.</param>
 /// <param name="cncBtn">The zero-based index of the cancel button.</param>
 /// <returns>The zero-based index of the button pressed.</returns>
 public static int Show(string message, string caption, CopyableMessageBoxIcon icon, IList<string> buttons, int defBtn, int cncBtn)
 {
     return Show(OwningForm, message, caption, icon, buttons, defBtn, cncBtn);
 }
Exemple #9
0
 /// <summary>
 /// Displays a message box with the specified text, caption, icon, buttons, default button and cancel button.
 /// The text can be copied.
 /// </summary>
 /// <param name="message">The text to display in the message box.  This text can be copied.</param>
 /// <param name="caption">The text to display in the title bar of the message box.</param>
 /// <param name="buttons">One of the <see cref="CopyableMessageBoxButtons"/> values that specifies which buttons to display in the message box.</param>
 /// <param name="icon">One of the <see cref="CopyableMessageBoxIcon"/> values that specifies which icon to display in the message box.</param>
 /// <param name="defBtn">The zero-based index of the default button.</param>
 /// <param name="cncBtn">The zero-based index of the cancel button.</param>
 /// <returns>The zero-based index of the button pressed.</returns>
 public static int Show(string message, string caption, CopyableMessageBoxButtons buttons, CopyableMessageBoxIcon icon, int defBtn, int cncBtn)
 {
     return Show(message, caption, icon, enumToList(buttons), defBtn, cncBtn);
 }
Exemple #10
0
 /// <summary>
 /// Displays a message box with the specified text, caption, buttons, icon and default button.
 /// The text can be copied.
 /// </summary>
 /// <param name="message">The text to display in the message box.  This text can be copied.</param>
 /// <param name="caption">The text to display in the title bar of the message box.</param>
 /// <param name="buttons">One of the <see cref="CopyableMessageBoxButtons"/> values that specifies which buttons to display in the message box.
 /// If not specified, <see cref="CopyableMessageBoxButtons.OK"/> is used.</param>
 /// <param name="icon">One of the <see cref="CopyableMessageBoxIcon"/> values that specifies which icon to display in the message box.
 /// If not specified, <see cref="CopyableMessageBoxIcon.None"/> is used.</param>
 /// <param name="defBtn">The zero-based index of the default button.
 /// If not specified, <c>0</c> is used.</param>
 /// <returns>The zero-based index of the button pressed.</returns>
 public static int Show(string message, string caption,
     CopyableMessageBoxButtons buttons = CopyableMessageBoxButtons.OK,
     CopyableMessageBoxIcon icon = CopyableMessageBoxIcon.None,
     int defBtn = 0)
 {
     int cncBtn = enumToCncBtn(buttons);
     return Show(message, caption, icon, enumToList(buttons), defBtn, cncBtn);
 }
 /// <summary>
 /// Displays a message box with the specified text, caption, icon, buttons, default button and cancel button.
 /// The text can be copied.
 /// </summary>
 /// <param name="message">The text to display in the message box.  This text can be copied.</param>
 /// <param name="caption">The text to display in the title bar of the message box.</param>
 /// <param name="icon">One of the <see cref="CopyableMessageBoxIcon"/> values that specifies which icon to display in the message box.</param>
 /// <param name="buttons">A <see cref="IList{T}"/> (where <c>T</c> is <see cref="string"/>) to display as buttons in the message box.</param>
 /// <param name="defBtn">The zero-based index of the default button.</param>
 /// <param name="cncBtn">The zero-based index of the cancel button.</param>
 /// <returns>The zero-based index of the button pressed.</returns>
 public static int Show(string message, string caption, CopyableMessageBoxIcon icon, IList <string> buttons, int defBtn, int cncBtn)
 {
     return(Show(OwningForm, message, caption, icon, buttons, defBtn, cncBtn));
 }
 /// <summary>
 /// Displays a message box with the specified text, caption, icon, buttons, default button and cancel button.
 /// The text can be copied.
 /// </summary>
 /// <param name="message">The text to display in the message box.  This text can be copied.</param>
 /// <param name="caption">The text to display in the title bar of the message box.</param>
 /// <param name="buttons">One of the <see cref="CopyableMessageBoxButtons"/> values that specifies which buttons to display in the message box.</param>
 /// <param name="icon">One of the <see cref="CopyableMessageBoxIcon"/> values that specifies which icon to display in the message box.</param>
 /// <param name="defBtn">The zero-based index of the default button.</param>
 /// <param name="cncBtn">The zero-based index of the cancel button.</param>
 /// <returns>The zero-based index of the button pressed.</returns>
 public static int Show(string message, string caption, CopyableMessageBoxButtons buttons, CopyableMessageBoxIcon icon, int defBtn, int cncBtn)
 {
     return(Show(message, caption, icon, enumToList(buttons), defBtn, cncBtn));
 }