/// <summary>
            /// Shows the specified message box.
            /// </summary>
            /// <param name="owner">The owner.</param>
            /// <param name="text">The text.</param>
            /// <param name="caption">The caption.</param>
            /// <param name="buttons">The buttons.</param>
            /// <param name="icon">The icon.</param>
            /// <param name="defaultButton">The default button.</param>
            /// <returns>The dialog result.</returns>
            public static DialogResult Show(IWin32Window owner, string text, string caption, MessageBoxButtons buttons, MessageBoxIcon icon, MessageBoxDefaultButton defaultButton)
            {
                //Create a new instance of the FlexibleMessageBox form
                var flexibleMessageBoxForm = new FlexibleMessageBoxForm();

                flexibleMessageBoxForm.ShowInTaskbar = false;

                //Bind the caption and the message text
                flexibleMessageBoxForm.CaptionText = caption;
                flexibleMessageBoxForm.MessageText = text;
                flexibleMessageBoxForm.FlexibleMessageBoxFormBindingSource.DataSource = flexibleMessageBoxForm;

                //Set the buttons visibilities and texts. Also set a default button.
                SetDialogButtons(flexibleMessageBoxForm, buttons, defaultButton);

                //Set the dialogs icon. When no icon is used: Correct placement and width of rich text box.
                SetDialogIcon(flexibleMessageBoxForm, icon);

                //Set the font for all controls
                flexibleMessageBoxForm.Font = FONT;
                flexibleMessageBoxForm.richTextBoxMessage.Font = FONT;

                //Calculate the dialogs start size (Try to auto-size width to show longest text row). Also set the maximum dialog size.
                SetDialogSizes(flexibleMessageBoxForm, text);

                //Set the dialogs start position when given. Otherwise center the dialog on the current screen.
                SetDialogStartPosition(flexibleMessageBoxForm, owner);

                //Show the dialog
                return(flexibleMessageBoxForm.ShowDialog(owner));
            }
Пример #2
0
            /// <summary>
            /// Calculate the dialogs start size (Try to auto-size width to show longest text row).
            /// Also set the maximum dialog size.
            /// </summary>
            /// <param name="flexibleMessageBoxForm">The FlexibleMessageBox dialog.</param>
            /// <param name="text">The text (the longest text row is used to calculate the dialog width).</param>
            /// <param name="text">The caption (this can also affect the dialog width).</param>
            private static void SetDialogSizes(FlexibleMessageBoxForm flexibleMessageBoxForm, string text, string caption)
            {
                //First set the bounds for the maximum dialog size
                flexibleMessageBoxForm.MaximumSize = new Size(Convert.ToInt32(SystemInformation.WorkingArea.Width * FlexibleMessageBoxForm.GetCorrectedWorkingAreaFactor(MAX_WIDTH_FACTOR)),
                                                              Convert.ToInt32(SystemInformation.WorkingArea.Height * FlexibleMessageBoxForm.GetCorrectedWorkingAreaFactor(MAX_HEIGHT_FACTOR)));

                //Get rows. Exit if there are no rows to render...
                var stringRows = GetStringRows(text);

                if (stringRows == null)
                {
                    return;
                }

                //Calculate whole text height
                var textHeight = TextRenderer.MeasureText(text, FONT).Height;

                //Calculate width for longest text line
                const int SCROLLBAR_WIDTH_OFFSET = 15;
                var       longestTextRowWidth    = stringRows.Max(textForRow => TextRenderer.MeasureText(textForRow, FONT).Width);
                var       captionWidth           = TextRenderer.MeasureText(caption, SystemFonts.CaptionFont).Width;
                var       textWidth = Math.Max(longestTextRowWidth + SCROLLBAR_WIDTH_OFFSET, captionWidth);

                //Calculate margins
                var marginWidth  = flexibleMessageBoxForm.Width - flexibleMessageBoxForm.richTextBoxMessage.Width;
                var marginHeight = flexibleMessageBoxForm.Height - flexibleMessageBoxForm.richTextBoxMessage.Height;

                //Set calculated dialog size (if the calculated values exceed the maximums, they were cut by windows forms automatically)
                flexibleMessageBoxForm.Size = new Size(textWidth + marginWidth,
                                                       textHeight + marginHeight);
            }
            /// <summary>
            /// Calculate the dialogs start size (Try to auto-size width to show longest text row).
            /// Also set the maximum dialog size.
            /// </summary>
            /// <param name="flexibleMessageBoxForm">The FlexibleMessageBox dialog.</param>
            /// <param name="text">The text (the longest text row is used to calculate the dialog width).</param>
            private static void SetDialogSizes(FlexibleMessageBoxForm flexibleMessageBoxForm, string text)
            {
                //Set maximum dialog size
                flexibleMessageBoxForm.MaximumSize = new Size(Convert.ToInt32(SystemInformation.WorkingArea.Width * FlexibleMessageBoxForm.GetCorrectedWorkingAreaFactor(MAX_WIDTH_FACTOR)),
                                                              Convert.ToInt32(SystemInformation.WorkingArea.Height * FlexibleMessageBoxForm.GetCorrectedWorkingAreaFactor(MAX_HEIGHT_FACTOR)));

                //Calculate dialog start size: Try to auto-size width to show longest text row
                var rowSize          = Size.Empty;
                var maxTextRowWidth  = 0;
                var maxTextRowHeight = 0f;
                var stringRows       = GetStringRows(text);

                using (var graphics = flexibleMessageBoxForm.CreateGraphics())
                {
                    maxTextRowHeight = graphics.MeasureString(" ", FONT).Height;

                    foreach (var textForRow in stringRows)
                    {
                        rowSize = graphics.MeasureString(textForRow, FONT, flexibleMessageBoxForm.MaximumSize.Width).ToSize();
                        if (rowSize.Width > maxTextRowWidth)
                        {
                            maxTextRowWidth = rowSize.Width;
                        }
                    }
                }

                //Set dialog start size
                flexibleMessageBoxForm.Size = new Size(maxTextRowWidth + flexibleMessageBoxForm.Width - flexibleMessageBoxForm.richTextBoxMessage.Width + 10,
                                                       Convert.ToInt32(maxTextRowHeight * stringRows.Count()) + flexibleMessageBoxForm.Height - flexibleMessageBoxForm.richTextBoxMessage.Height + 10);
            }
            /// <summary>
            /// Set the dialogs icon.
            /// When no icon is used: Correct placement and width of rich text box.
            /// </summary>
            /// <param name="flexibleMessageBoxForm">The FlexibleMessageBox dialog.</param>
            /// <param name="icon">The MessageBoxIcon.</param>
            private static void SetDialogIcon(FlexibleMessageBoxForm flexibleMessageBoxForm, MessageBoxIcon icon)
            {
                switch (icon)
                {
                case MessageBoxIcon.Information:
                    flexibleMessageBoxForm.pictureBoxForIcon.Image = SystemIcons.Information.ToBitmap();
                    break;

                case MessageBoxIcon.Warning:
                    flexibleMessageBoxForm.pictureBoxForIcon.Image = SystemIcons.Warning.ToBitmap();
                    break;

                case MessageBoxIcon.Error:
                    flexibleMessageBoxForm.pictureBoxForIcon.Image = SystemIcons.Error.ToBitmap();
                    break;

                case MessageBoxIcon.Question:
                    flexibleMessageBoxForm.pictureBoxForIcon.Image = SystemIcons.Question.ToBitmap();
                    break;

                default:
                    //When no icon is used: Correct placement and width of rich text box.
                    flexibleMessageBoxForm.pictureBoxForIcon.Visible = false;
                    flexibleMessageBoxForm.richTextBoxMessage.Left  -= flexibleMessageBoxForm.pictureBoxForIcon.Width;
                    flexibleMessageBoxForm.richTextBoxMessage.Width += flexibleMessageBoxForm.pictureBoxForIcon.Width;
                    break;
                }
            }
Пример #5
0
            // Added ability to have custom text on the buttons - BoltBait
            private static void SetCustomDialogButtons(FlexibleMessageBoxForm flexibleMessageBoxForm, string[] buttons, MessageBoxDefaultButton defaultButton)
            {
                if (buttons.Length > 3)
                {
                    throw new Exception("Maximum of 3 buttons can be defined.");
                }
                if (buttons.Length < 1)
                {
                    SetDialogButtons(flexibleMessageBoxForm, MessageBoxButtons.OK, MessageBoxDefaultButton.Button1);
                    return;
                }
                switch (buttons.Length)
                {
                case 1:      // returns 1 - Pressing ESC returns 1
                    flexibleMessageBoxForm.visibleButtonsCount  = 1;
                    flexibleMessageBoxForm.button3.Visible      = true;
                    flexibleMessageBoxForm.button3.Text         = buttons[0];
                    flexibleMessageBoxForm.button3.DialogResult = DialogResult.OK;

                    flexibleMessageBoxForm.CancelButton = flexibleMessageBoxForm.button3;
                    break;

                case 2:      // returns 1 or 2 - Pressing ESC returns 2
                    flexibleMessageBoxForm.button3.Visible      = true;
                    flexibleMessageBoxForm.button3.Text         = buttons[1];
                    flexibleMessageBoxForm.button3.DialogResult = DialogResult.Cancel;

                    flexibleMessageBoxForm.visibleButtonsCount  = 2;
                    flexibleMessageBoxForm.button2.Visible      = true;
                    flexibleMessageBoxForm.button2.Text         = buttons[0];
                    flexibleMessageBoxForm.button2.DialogResult = DialogResult.OK;
                    flexibleMessageBoxForm.button2.Location     = new Point(
                        flexibleMessageBoxForm.button3.Location.X - ButtonMargin - flexibleMessageBoxForm.button2.Bounds.Width,
                        flexibleMessageBoxForm.button2.Location.Y);

                    flexibleMessageBoxForm.CancelButton = flexibleMessageBoxForm.button3;
                    break;

                case 3:      // returns 1 or 2 or 3 - Pressing ESC returns 3
                    flexibleMessageBoxForm.visibleButtonsCount  = 3;
                    flexibleMessageBoxForm.button1.Visible      = true;
                    flexibleMessageBoxForm.button1.Text         = buttons[0];
                    flexibleMessageBoxForm.button1.DialogResult = DialogResult.OK;

                    flexibleMessageBoxForm.button2.Visible      = true;
                    flexibleMessageBoxForm.button2.Text         = buttons[1];
                    flexibleMessageBoxForm.button2.DialogResult = DialogResult.Cancel;

                    flexibleMessageBoxForm.button3.Visible      = true;
                    flexibleMessageBoxForm.button3.Text         = buttons[2];
                    flexibleMessageBoxForm.button3.DialogResult = DialogResult.Abort;

                    flexibleMessageBoxForm.CancelButton = flexibleMessageBoxForm.button3;
                    break;
                }
                flexibleMessageBoxForm.ControlBox = false;

                //Set default button (used in FlexibleMessageBoxForm_Shown)
                flexibleMessageBoxForm.defaultButton = defaultButton;
            }
 /// <summary>
 /// Shows the specified message box.
 /// </summary>
 /// <param name="owner">The owner.</param>
 /// <param name="text">The text.</param>
 /// <param name="caption">The caption.</param>
 /// <param name="buttons">The buttons.</param>
 /// <param name="icon">The icon.</param>
 /// <param name="defaultButton">The default button.</param>
 /// <param name="linkClickedAction">optional handler if user clicks a hyperlink (as determined by RichTextBox). Set to
 /// <seealso cref="BasicLinkClickedEventHandler"/> to get basic handling. If <c>null</c>, URLs will not be detected or
 /// highlighted in the message.</param>
 /// <returns>The dialog result.</returns>
 /// <returns>The dialog result.</returns>
 /// <exception cref="Exception">Exceptions might be thrown by the <paramref name="linkClickedAction"/></exception>
 internal static DialogResult Show(IWin32Window owner, string text, string caption, MessageBoxButtons buttons,
                                   MessageBoxIcon icon, MessageBoxDefaultButton defaultButton, LinkClickedEventHandler linkClickedAction = null)
 {
     // Create a new instance of the FlexibleMessageBox form
     using (var flexibleMessageBoxForm = new FlexibleMessageBoxForm(owner, text, caption, buttons,
                                                                    icon, defaultButton, linkClickedAction))
         return(flexibleMessageBoxForm.ShowDialog(owner));
 }
Пример #7
0
            /// <summary>
            /// Calculate the dialogs start size (Try to auto-size width to show longest text row).
            /// Also set the maximum dialog size.
            /// </summary>
            /// <param name="flexibleMessageBoxForm">The FlexibleMessageBox dialog.</param>
            /// <param name="text">The text (the longest text row is used to calculate the dialog width).</param>
            /// <param name="text">The caption (this can also affect the dialog width).</param>
            private static void SetDialogSizesEx(FlexibleMessageBoxForm flexibleMessageBoxForm, string text, string caption, int width, int height)
            {
                //First set the bounds for the maximum dialog size
                flexibleMessageBoxForm.MaximumSize = new Size(width, height);

                //Set calculated dialog size (if the calculated values exceed the maximums, they were cut by windows forms automatically)
                flexibleMessageBoxForm.Size = new Size(width, height);
            }
 /// <summary>
 ///     Shows the specified message box.
 /// </summary>
 /// <param name="owner">The owner.</param>
 /// <param name="text">The text.</param>
 /// <param name="caption">The caption.</param>
 /// <param name="buttons">The buttons.</param>
 /// <param name="icon">The icon.</param>
 /// <param name="defaultButton">The default button.</param>
 /// <returns>The dialog result.</returns>
 public static DialogResult Show(IWin32Window owner,
                                 string text,
                                 string caption,
                                 MessageBoxButtons buttons,
                                 MessageBoxIcon icon,
                                 MessageBoxDefaultButton defaultButton)
 {
     return(FlexibleMessageBoxForm.Show(owner, text, caption, buttons, icon, defaultButton));
 }
Пример #9
0
 /// <summary>
 /// Set the dialogs start position when given.
 /// Otherwise center the dialog on the current screen.
 /// </summary>
 /// <param name="flexibleMessageBoxForm">The FlexibleMessageBox dialog.</param>
 /// <param name="owner">The owner.</param>
 private static void SetDialogStartPosition(FlexibleMessageBoxForm flexibleMessageBoxForm, IWin32Window owner)
 {
     //If no owner given: Center on current screen
     if (owner == null)
     {
         var screen = Screen.FromPoint(Cursor.Position);
         flexibleMessageBoxForm.StartPosition = FormStartPosition.Manual;
         flexibleMessageBoxForm.Left          = screen.Bounds.Left + screen.Bounds.Width / 2 - flexibleMessageBoxForm.Width / 2;
         flexibleMessageBoxForm.Top           = screen.Bounds.Top + screen.Bounds.Height / 2 - flexibleMessageBoxForm.Height / 2;
     }
 }
Пример #10
0
            /// <summary>
            /// Shows the specified message box.
            /// </summary>
            /// <param name="owner">The owner.</param>
            /// <param name="text">The text.</param>
            /// <param name="caption">The caption.</param>
            /// <param name="buttons">The buttons.</param>
            /// <param name="icon">The icon.</param>
            /// <param name="parent">The parent window.</param>
            /// <param name="lines">Amount of lines.</param>
            /// <returns>The dialog result.</returns>
            public static DialogResult Show(IWin32Window owner, string text, string caption, MessageBoxButtons buttons, MessageBoxIcon icon, Form parent, int lines)
            {
                //Create a new instance of the FlexibleMessageBox form
                var flexibleMessageBoxForm = new FlexibleMessageBoxForm();

                flexibleMessageBoxForm.ShowInTaskbar = false;

                //Bind the caption and the message text
                flexibleMessageBoxForm.CaptionText = caption;
                flexibleMessageBoxForm.MessageText = text;
                flexibleMessageBoxForm.FlexibleMessageBoxFormBindingSource.DataSource = flexibleMessageBoxForm;

                //Set the buttons visibilities and texts. Also set a default button.
                SetDialogButtons(flexibleMessageBoxForm, buttons, MessageBoxDefaultButton.Button1);

                //Set the dialogs icon. When no icon is used: Correct placement and width of rich text box.
                SetDialogIcon(flexibleMessageBoxForm, icon);

                //Set the font for all controls
                flexibleMessageBoxForm.Font = FONT;
                flexibleMessageBoxForm.richTextBoxMessage.Font = FONT;

                //Calculate the dialogs start size (Try to auto-size width to show longest text row). Also set the maximum dialog size.
                SetDialogSizesEx(flexibleMessageBoxForm, text, caption, parent.Width, parent.Height);

                //Set the dialogs start position when given. Otherwise center the dialog on the current screen.
                SetDialogStartPosition(flexibleMessageBoxForm, owner);

                if (icon != MessageBoxIcon.None)
                {
                    // Center some elements.
                    flexibleMessageBoxForm.pictureBoxForIcon.Location  = new Point(15, flexibleMessageBoxForm.panel1.Height / 2 - 16);
                    flexibleMessageBoxForm.richTextBoxMessage.Location = new Point(60, flexibleMessageBoxForm.panel1.Height / 2 - ((15 / 2) * lines));
                }

                else
                {
                    flexibleMessageBoxForm.richTextBoxMessage.Location = new Point(15, flexibleMessageBoxForm.panel1.Height / 2 - ((15 / 2) * lines));
                }

                //Show the dialog
                return(flexibleMessageBoxForm.ShowDialog(owner));
            }
Пример #11
0
 /// <summary>
 /// Set the dialogs icon. 
 /// When no icon is used: Correct placement and width of rich text box.
 /// </summary>
 /// <param name="flexibleMessageBoxForm">The FlexibleMessageBox dialog.</param>
 /// <param name="icon">The MessageBoxIcon.</param>
 private static void SetDialogIcon(FlexibleMessageBoxForm flexibleMessageBoxForm, MessageBoxIcon icon)
 {
     switch (icon)
     {
         case MessageBoxIcon.Information:
             flexibleMessageBoxForm.pictureBoxForIcon.Image = SystemIcons.Information.ToBitmap();
             break;
         case MessageBoxIcon.Warning:
             flexibleMessageBoxForm.pictureBoxForIcon.Image = SystemIcons.Warning.ToBitmap();
             break;
         case MessageBoxIcon.Error:
             flexibleMessageBoxForm.pictureBoxForIcon.Image = SystemIcons.Error.ToBitmap();
             break;
         case MessageBoxIcon.Question:
             flexibleMessageBoxForm.pictureBoxForIcon.Image = SystemIcons.Question.ToBitmap();
             break;
         default:
             //When no icon is used: Correct placement and width of rich text box.
             flexibleMessageBoxForm.pictureBoxForIcon.Visible = false;
             flexibleMessageBoxForm.richTextBoxMessage.Left -= flexibleMessageBoxForm.pictureBoxForIcon.Width;
             flexibleMessageBoxForm.richTextBoxMessage.Width += flexibleMessageBoxForm.pictureBoxForIcon.Width;
             break;
     }
 }
Пример #12
0
 /// <summary>
 /// Shows the specified message box.
 /// </summary>
 /// <param name="text">The text.</param>
 /// <returns>The dialog result.</returns>
 public static DialogResult Show(string text)
 {
     return(FlexibleMessageBoxForm.Show(null, text, string.Empty, MessageBoxButtons.OK, MessageBoxIcon.None, MessageBoxDefaultButton.Button1));
 }
Пример #13
0
 // Added ability to have custom button text - BoltBait
 public static DialogResult Show(string text, string caption, string[] buttons, MessageBoxIcon icon, MessageBoxDefaultButton defaultButton)
 {
     return(FlexibleMessageBoxForm.Show(null, text, caption, buttons, icon, defaultButton));
 }
Пример #14
0
            /// <summary>
            /// Shows the specified message box.
            /// </summary>
            /// <param name="owner">The owner.</param>
            /// <param name="text">The text.</param>
            /// <param name="caption">The caption.</param>
            /// <param name="buttons">The buttons.</param>
            /// <param name="icon">The icon.</param>
            /// <param name="defaultButton">The default button.</param>
            /// <returns>The dialog result.</returns>
            public static DialogResult Show(IWin32Window owner, string text, string caption, MessageBoxButtons buttons, MessageBoxIcon icon, MessageBoxDefaultButton defaultButton)
            {
                //Create a new instance of the FlexibleMessageBox form
                var flexibleMessageBoxForm = new FlexibleMessageBoxForm();

                //Bind the caption and the message text
                flexibleMessageBoxForm.CaptionText = caption;
                flexibleMessageBoxForm.MessageText = text;
                flexibleMessageBoxForm.FlexibleMessageBoxFormBindingSource.DataSource = flexibleMessageBoxForm;

                //Set the buttons visibilities and texts. Also set a default button.
                SetDialogButtons(flexibleMessageBoxForm, buttons, defaultButton);

                //Set the dialogs icon. When no icon is used: Correct placement and width of rich text box.
                SetDialogIcon(flexibleMessageBoxForm, icon);

                //Set the font for all controls
                flexibleMessageBoxForm.Font = FONT;
                flexibleMessageBoxForm.richTextBoxMessage.Font = FONT;

                //Calculate the dialogs start size (Try to auto-size width to show longest text row). Also set the maximum dialog size.
                SetDialogSizes(flexibleMessageBoxForm, text);

                //Set the dialogs start position when given. Otherwise center the dialog on the current screen.
                SetDialogStartPosition(flexibleMessageBoxForm, owner);

                //Show the dialog
                return flexibleMessageBoxForm.ShowDialog(owner);
            }
Пример #15
0
 /// <summary>
 /// Shows the specified message box.
 /// </summary>
 /// <param name="owner">The owner.</param>
 /// <param name="text">The text.</param>
 /// <param name="caption">The caption.</param>
 /// <param name="buttons">The buttons.</param>
 /// <param name="icon">The icon.</param>
 /// <param name="parent">The parent window.</param>
 /// <param name="lines">Amount of lines.</param>
 /// <returns>The dialog result.</returns>
 public static DialogResult Show(IWin32Window owner, string text, string caption, MessageBoxButtons buttons, MessageBoxIcon icon, Form parent, int lines)
 {
     return(FlexibleMessageBoxForm.Show(owner, text, caption, buttons, icon, parent, lines));
 }
Пример #16
0
 /// <summary>
 /// Shows the specified message box.
 /// </summary>
 /// <param name="text">The text.</param>
 /// <param name="caption">The caption.</param>
 /// <param name="buttons">The buttons.</param>
 /// <param name="icon">The icon.</param>
 /// <param name="linkClickedAction">optional handler if user clicks a hyperlink (as determined by RichTextBox). Set to
 /// <seealso cref="BasicLinkClickedEventHandler"/> to get basic handling. If <c>null</c>, URLs will not be detected or
 /// highlighted in the message.</param>
 /// <returns>The dialog result.</returns>
 /// <returns></returns>
 public static DialogResult Show(string text, string caption, MessageBoxButtons buttons, MessageBoxIcon icon, LinkClickedEventHandler linkClickedAction = null)
 {
     return(FlexibleMessageBoxForm.Show(null, text, caption, buttons, icon, MessageBoxDefaultButton.Button1, linkClickedAction));
 }
Пример #17
0
 /// <summary>
 /// Shows the specified message box.
 /// </summary>
 /// <param name="owner">The owner.</param>
 /// <param name="text">The text.</param>
 /// <param name="caption">The caption.</param>
 /// <param name="buttons">The buttons.</param>
 /// <param name="icon">The icon.</param>
 /// <param name="defaultButton">The default button.</param>
 /// <param name="linkClickedAction">optional handler if user clicks a hyperlink (as determined by RichTextBox). Set to
 /// <seealso cref="BasicLinkClickedEventHandler"/> to get basic handling. If <c>null</c>, URLs will not be detected or
 /// highlighted in the message.</param>
 /// <returns>The dialog result.</returns>
 /// <returns>The dialog result.</returns>
 public static DialogResult Show(IWin32Window owner, string text, string caption, MessageBoxButtons buttons,
                                 MessageBoxIcon icon, MessageBoxDefaultButton defaultButton, LinkClickedEventHandler linkClickedAction = null)
 {
     return(FlexibleMessageBoxForm.Show(owner, text, caption, buttons, icon, defaultButton, linkClickedAction));
 }
Пример #18
0
 /// <summary>
 /// Shows the specified message box.
 /// </summary>
 /// <param name="owner">The owner.</param>
 /// <param name="text">The text.</param>
 /// <param name="linkClickedAction">optional handler if user clicks a hyperlink (as determined by RichTextBox). Set to
 /// <seealso cref="BasicLinkClickedEventHandler"/> to get basic handling. If <c>null</c>, URLs will not be detected or
 /// highlighted in the message.</param>
 /// <returns>The dialog result.</returns>
 /// <returns>The dialog result.</returns>
 public static DialogResult Show(IWin32Window owner, string text, LinkClickedEventHandler linkClickedAction = null)
 {
     return(FlexibleMessageBoxForm.Show(owner, text, string.Empty, MessageBoxButtons.OK, MessageBoxIcon.None, MessageBoxDefaultButton.Button1, linkClickedAction));
 }
Пример #19
0
 public static DialogResult Show(Exception ex, string caption)
 {
     return(FlexibleMessageBoxForm.Show(null, string.Format("Error Details:{1}{1}{0}{1}{2}", ex.Message, Environment.NewLine, ex.StackTrace), caption, MessageBoxButtons.OK, MessageBoxIcon.None, MessageBoxDefaultButton.Button1));
 }
Пример #20
0
 /// <summary>
 /// Shows the specified message box.
 /// </summary>
 /// <param name="text">The text.</param>
 /// <param name="caption">The caption.</param>
 /// <param name="buttons">The buttons.</param>
 /// <returns>The dialog result.</returns>
 public static DialogResult Show(string text, string caption, MessageBoxButtons buttons)
 {
     return(FlexibleMessageBoxForm.Show(null, text, caption, buttons, MessageBoxIcon.None, MessageBoxDefaultButton.Button1));
 }
Пример #21
0
            /// <summary>
            /// Set dialog buttons visibilities and texts.
            /// Also set a default button.
            /// </summary>
            /// <param name="flexibleMessageBoxForm">The FlexibleMessageBox dialog.</param>
            /// <param name="buttons">The buttons.</param>
            /// <param name="defaultButton">The default button.</param>
            private static void SetDialogButtons(FlexibleMessageBoxForm flexibleMessageBoxForm, MessageBoxButtons buttons, MessageBoxDefaultButton defaultButton)
            {
                //Set the buttons visibilities and texts
                switch (buttons)
                {
                case MessageBoxButtons.AbortRetryIgnore:
                    flexibleMessageBoxForm.visibleButtonsCount = 3;

                    flexibleMessageBoxForm.button1.Visible      = true;
                    flexibleMessageBoxForm.button1.Text         = flexibleMessageBoxForm.GetButtonText(ButtonID.ABORT);
                    flexibleMessageBoxForm.button1.DialogResult = DialogResult.Abort;

                    flexibleMessageBoxForm.button2.Visible      = true;
                    flexibleMessageBoxForm.button2.Text         = flexibleMessageBoxForm.GetButtonText(ButtonID.RETRY);
                    flexibleMessageBoxForm.button2.DialogResult = DialogResult.Retry;

                    flexibleMessageBoxForm.button3.Visible      = true;
                    flexibleMessageBoxForm.button3.Text         = flexibleMessageBoxForm.GetButtonText(ButtonID.IGNORE);
                    flexibleMessageBoxForm.button3.DialogResult = DialogResult.Ignore;

                    flexibleMessageBoxForm.ControlBox = false;
                    break;

                case MessageBoxButtons.OKCancel:
                    flexibleMessageBoxForm.visibleButtonsCount = 2;

                    flexibleMessageBoxForm.button2.Visible      = true;
                    flexibleMessageBoxForm.button2.Text         = flexibleMessageBoxForm.GetButtonText(ButtonID.OK);
                    flexibleMessageBoxForm.button2.DialogResult = DialogResult.OK;

                    flexibleMessageBoxForm.button3.Visible      = true;
                    flexibleMessageBoxForm.button3.Text         = flexibleMessageBoxForm.GetButtonText(ButtonID.CANCEL);
                    flexibleMessageBoxForm.button3.DialogResult = DialogResult.Cancel;

                    flexibleMessageBoxForm.CancelButton = flexibleMessageBoxForm.button3;
                    break;

                case MessageBoxButtons.RetryCancel:
                    flexibleMessageBoxForm.visibleButtonsCount = 2;

                    flexibleMessageBoxForm.button2.Visible      = true;
                    flexibleMessageBoxForm.button2.Text         = flexibleMessageBoxForm.GetButtonText(ButtonID.RETRY);
                    flexibleMessageBoxForm.button2.DialogResult = DialogResult.Retry;

                    flexibleMessageBoxForm.button3.Visible      = true;
                    flexibleMessageBoxForm.button3.Text         = flexibleMessageBoxForm.GetButtonText(ButtonID.CANCEL);
                    flexibleMessageBoxForm.button3.DialogResult = DialogResult.Cancel;

                    flexibleMessageBoxForm.CancelButton = flexibleMessageBoxForm.button3;
                    break;

                case MessageBoxButtons.YesNo:
                    flexibleMessageBoxForm.visibleButtonsCount = 2;

                    flexibleMessageBoxForm.button2.Visible      = true;
                    flexibleMessageBoxForm.button2.Text         = flexibleMessageBoxForm.GetButtonText(ButtonID.YES);
                    flexibleMessageBoxForm.button2.DialogResult = DialogResult.Yes;

                    flexibleMessageBoxForm.button3.Visible      = true;
                    flexibleMessageBoxForm.button3.Text         = flexibleMessageBoxForm.GetButtonText(ButtonID.NO);
                    flexibleMessageBoxForm.button3.DialogResult = DialogResult.No;

                    flexibleMessageBoxForm.ControlBox = false;
                    break;

                case MessageBoxButtons.YesNoCancel:
                    flexibleMessageBoxForm.visibleButtonsCount = 3;

                    flexibleMessageBoxForm.button1.Visible      = true;
                    flexibleMessageBoxForm.button1.Text         = flexibleMessageBoxForm.GetButtonText(ButtonID.YES);
                    flexibleMessageBoxForm.button1.DialogResult = DialogResult.Yes;

                    flexibleMessageBoxForm.button2.Visible      = true;
                    flexibleMessageBoxForm.button2.Text         = flexibleMessageBoxForm.GetButtonText(ButtonID.NO);
                    flexibleMessageBoxForm.button2.DialogResult = DialogResult.No;

                    flexibleMessageBoxForm.button3.Visible      = true;
                    flexibleMessageBoxForm.button3.Text         = flexibleMessageBoxForm.GetButtonText(ButtonID.CANCEL);
                    flexibleMessageBoxForm.button3.DialogResult = DialogResult.Cancel;

                    flexibleMessageBoxForm.CancelButton = flexibleMessageBoxForm.button3;
                    break;

                case MessageBoxButtons.OK:
                default:
                    flexibleMessageBoxForm.visibleButtonsCount  = 1;
                    flexibleMessageBoxForm.button3.Visible      = true;
                    flexibleMessageBoxForm.button3.Text         = flexibleMessageBoxForm.GetButtonText(ButtonID.OK);
                    flexibleMessageBoxForm.button3.DialogResult = DialogResult.OK;

                    flexibleMessageBoxForm.CancelButton = flexibleMessageBoxForm.button3;
                    break;
                }

                //Set default button (used in FlexibleMessageBoxForm_Shown)
                flexibleMessageBoxForm.defaultButton = defaultButton;
            }
Пример #22
0
            /// <summary>
            /// Set dialog buttons visibilities and texts. 
            /// Also set a default button.
            /// </summary>
            /// <param name="flexibleMessageBoxForm">The FlexibleMessageBox dialog.</param>
            /// <param name="buttons">The buttons.</param>
            /// <param name="defaultButton">The default button.</param>
            private static void SetDialogButtons(FlexibleMessageBoxForm flexibleMessageBoxForm, MessageBoxButtons buttons, MessageBoxDefaultButton defaultButton)
            {
                //Set the buttons visibilities and texts
                switch (buttons)
                {
                    case MessageBoxButtons.AbortRetryIgnore:
                        flexibleMessageBoxForm._visibleButtonsCount = 3;

                        flexibleMessageBoxForm.button1.Visible = true;
                        flexibleMessageBoxForm.button1.Text = flexibleMessageBoxForm.GetButtonText(BUTTON_TEXT.ABORT);
                        flexibleMessageBoxForm.button1.DialogResult = DialogResult.Abort;

                        flexibleMessageBoxForm.button2.Visible = true;
                        flexibleMessageBoxForm.button2.Text = flexibleMessageBoxForm.GetButtonText(BUTTON_TEXT.RETRY);
                        flexibleMessageBoxForm.button2.DialogResult = DialogResult.Retry;

                        flexibleMessageBoxForm.button3.Visible = true;
                        flexibleMessageBoxForm.button3.Text = flexibleMessageBoxForm.GetButtonText(BUTTON_TEXT.IGNORE);
                        flexibleMessageBoxForm.button3.DialogResult = DialogResult.Ignore;
                        break;

                    case MessageBoxButtons.OKCancel:
                        flexibleMessageBoxForm._visibleButtonsCount = 2;

                        flexibleMessageBoxForm.button2.Visible = true;
                        flexibleMessageBoxForm.button2.Text = flexibleMessageBoxForm.GetButtonText(BUTTON_TEXT.OK);
                        flexibleMessageBoxForm.button2.DialogResult = DialogResult.OK;

                        flexibleMessageBoxForm.button3.Visible = true;
                        flexibleMessageBoxForm.button3.Text = flexibleMessageBoxForm.GetButtonText(BUTTON_TEXT.CANCEL);
                        flexibleMessageBoxForm.button3.DialogResult = DialogResult.Cancel;
                        break;

                    case MessageBoxButtons.RetryCancel:
                        flexibleMessageBoxForm._visibleButtonsCount = 2;

                        flexibleMessageBoxForm.button2.Visible = true;
                        flexibleMessageBoxForm.button2.Text = flexibleMessageBoxForm.GetButtonText(BUTTON_TEXT.RETRY);
                        flexibleMessageBoxForm.button2.DialogResult = DialogResult.Retry;

                        flexibleMessageBoxForm.button3.Visible = true;
                        flexibleMessageBoxForm.button3.Text = flexibleMessageBoxForm.GetButtonText(BUTTON_TEXT.CANCEL);
                        flexibleMessageBoxForm.button3.DialogResult = DialogResult.Cancel;
                        break;

                    case MessageBoxButtons.YesNo:
                        flexibleMessageBoxForm._visibleButtonsCount = 2;

                        flexibleMessageBoxForm.button2.Visible = true;
                        flexibleMessageBoxForm.button2.Text = flexibleMessageBoxForm.GetButtonText(BUTTON_TEXT.YES);
                        flexibleMessageBoxForm.button2.DialogResult = DialogResult.Yes;

                        flexibleMessageBoxForm.button3.Visible = true;
                        flexibleMessageBoxForm.button3.Text = flexibleMessageBoxForm.GetButtonText(BUTTON_TEXT.NO);
                        flexibleMessageBoxForm.button3.DialogResult = DialogResult.No;
                        break;

                    case MessageBoxButtons.YesNoCancel:
                        flexibleMessageBoxForm._visibleButtonsCount = 3;

                        flexibleMessageBoxForm.button1.Visible = true;
                        flexibleMessageBoxForm.button1.Text = flexibleMessageBoxForm.GetButtonText(BUTTON_TEXT.YES);
                        flexibleMessageBoxForm.button1.DialogResult = DialogResult.Yes;

                        flexibleMessageBoxForm.button2.Visible = true;
                        flexibleMessageBoxForm.button2.Text = flexibleMessageBoxForm.GetButtonText(BUTTON_TEXT.NO);
                        flexibleMessageBoxForm.button2.DialogResult = DialogResult.No;

                        flexibleMessageBoxForm.button3.Visible = true;
                        flexibleMessageBoxForm.button3.Text = flexibleMessageBoxForm.GetButtonText(BUTTON_TEXT.CANCEL);
                        flexibleMessageBoxForm.button3.DialogResult = DialogResult.Cancel;
                        break;

                    case MessageBoxButtons.OK:
                    default:
                        flexibleMessageBoxForm._visibleButtonsCount = 1;
                        flexibleMessageBoxForm.button3.Visible = true;
                        flexibleMessageBoxForm.button3.Text = flexibleMessageBoxForm.GetButtonText(BUTTON_TEXT.OK);
                        flexibleMessageBoxForm.button3.DialogResult = DialogResult.OK;
                        break;
                }

                //Set default button (used in FlexibleMessageBoxForm_Shown)
                flexibleMessageBoxForm._defaultButton = defaultButton;
            }
Пример #23
0
 /// <summary>
 /// Shows the specified message box.
 /// </summary>
 /// <param name="owner">The owner.</param>
 /// <param name="text">The text.</param>
 /// <param name="caption">The caption.</param>
 /// <returns>The dialog result.</returns>
 public static DialogResult Show(IWin32Window owner, string text, string caption)
 {
     return(FlexibleMessageBoxForm.Show(owner, text, caption, MessageBoxButtons.OK, MessageBoxIcon.None, MessageBoxDefaultButton.Button1));
 }
Пример #24
0
            /// <summary>
            /// Calculate the dialogs start size (Try to auto-size width to show longest text row).
            /// Also set the maximum dialog size. 
            /// </summary>
            /// <param name="flexibleMessageBoxForm">The FlexibleMessageBox dialog.</param>
            /// <param name="text">The text (the longest text row is used to calculate the dialog width).</param>
            private static void SetDialogSizes(FlexibleMessageBoxForm flexibleMessageBoxForm, string text)
            {
                //Set maximum dialog size
                flexibleMessageBoxForm.MaximumSize = new Size(Convert.ToInt32(SystemInformation.WorkingArea.Width * FlexibleMessageBoxForm.GetCorrectedWorkingAreaFactor(MAX_WIDTH_FACTOR)),
                                                              Convert.ToInt32(SystemInformation.WorkingArea.Height * FlexibleMessageBoxForm.GetCorrectedWorkingAreaFactor(MAX_HEIGHT_FACTOR)));

                //Calculate dialog start size: Try to auto-size width to show longest text row
                var rowSize = Size.Empty;
                var maxTextRowWidth = 0;
                var maxTextRowHeight = 0f;
                var stringRows = GetStringRows(text);
                using (var graphics = flexibleMessageBoxForm.CreateGraphics())
                {
                    maxTextRowHeight = graphics.MeasureString(" ", FONT).Height;

                    foreach (var textForRow in stringRows)
                    {
                        rowSize = graphics.MeasureString(textForRow, FONT, flexibleMessageBoxForm.MaximumSize.Width).ToSize();
                        if (rowSize.Width > maxTextRowWidth) maxTextRowWidth = rowSize.Width;
                    }
                }

                //Set dialog start size
                flexibleMessageBoxForm.Size = new Size(maxTextRowWidth + flexibleMessageBoxForm.Width - flexibleMessageBoxForm.richTextBoxMessage.Width,
                                                   Convert.ToInt32(maxTextRowHeight * stringRows.Count()) + flexibleMessageBoxForm.Height - flexibleMessageBoxForm.richTextBoxMessage.Height);
            }
Пример #25
0
 /// <summary>
 /// Set the dialogs start position when given. 
 /// Otherwise center the dialog on the current screen.
 /// </summary>
 /// <param name="flexibleMessageBoxForm">The FlexibleMessageBox dialog.</param>
 /// <param name="owner">The owner.</param>
 private static void SetDialogStartPosition(FlexibleMessageBoxForm flexibleMessageBoxForm, IWin32Window owner)
 {
     //If no owner given: Center on current screen
     if (owner == null)
     {
         var screen = Screen.FromPoint(Cursor.Position);
         flexibleMessageBoxForm.StartPosition = FormStartPosition.Manual;
         flexibleMessageBoxForm.Left = screen.Bounds.Left + screen.Bounds.Width / 2 - flexibleMessageBoxForm.Width / 2;
         flexibleMessageBoxForm.Top = screen.Bounds.Top + screen.Bounds.Height / 2 - flexibleMessageBoxForm.Height / 2;
     }
 }
Пример #26
0
            /// <summary>
            /// Calculate the dialogs start size (Try to auto-size width to show longest text row).
            /// Also set the maximum dialog size. 
            /// </summary>
            /// <param name="flexibleMessageBoxForm">The FlexibleMessageBox dialog.</param>
            /// <param name="text">The text (the longest text row is used to calculate the dialog width).</param>
            /// <param name="text">The caption (this can also affect the dialog width).</param>
            private static void SetDialogSizes(FlexibleMessageBoxForm flexibleMessageBoxForm, string text, string caption)
            {
                //First set the bounds for the maximum dialog size
                flexibleMessageBoxForm.MaximumSize = new Size(Convert.ToInt32(SystemInformation.WorkingArea.Width * FlexibleMessageBoxForm.GetCorrectedWorkingAreaFactor(MAX_WIDTH_FACTOR)),
                                                              Convert.ToInt32(SystemInformation.WorkingArea.Height * FlexibleMessageBoxForm.GetCorrectedWorkingAreaFactor(MAX_HEIGHT_FACTOR)));

                //Get rows. Exit if there are no rows to render...
                var stringRows = GetStringRows(text);
                if (stringRows == null) return;

                //Calculate whole text height
                var textHeight = TextRenderer.MeasureText(text, FONT).Height;
                    
                //Calculate width for longest text line
                const int SCROLLBAR_WIDTH_OFFSET = 15;
                var longestTextRowWidth = stringRows.Max(textForRow => TextRenderer.MeasureText(textForRow, FONT).Width);
                var captionWidth = TextRenderer.MeasureText(caption, SystemFonts.CaptionFont).Width;
                var textWidth = Math.Max(longestTextRowWidth + SCROLLBAR_WIDTH_OFFSET, captionWidth);
                
                //Calculate margins
                var marginWidth = flexibleMessageBoxForm.Width - flexibleMessageBoxForm.richTextBoxMessage.Width;
                var marginHeight = flexibleMessageBoxForm.Height - flexibleMessageBoxForm.richTextBoxMessage.Height;

                //Set calculated dialog size (if the calculated values exceed the maximums, they were cut by windows forms automatically)
                flexibleMessageBoxForm.Size = new Size(textWidth + marginWidth,
                                                       textHeight + marginHeight);
            }