/// <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="FlexibleMaterialForm">The FlexibleMessageBox dialog.</param>
        /// <param name="text">The text (the longest text row is used to calculate the dialog width).</param>
        /// <param name="caption">The caption<see cref="string"/></param>
        private static void SetDialogSizes(FlexibleMaterialForm FlexibleMaterialForm, string text, string caption)
        {
            //First set the bounds for the maximum dialog size
            FlexibleMaterialForm.MaximumSize = new Size(Convert.ToInt32(SystemInformation.WorkingArea.Width * FlexibleMaterialForm.GetCorrectedWorkingAreaFactor(MAX_WIDTH_FACTOR)),
                                                        Convert.ToInt32(SystemInformation.WorkingArea.Height * FlexibleMaterialForm.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  = FlexibleMaterialForm.Width - FlexibleMaterialForm.richTextBoxMessage.Width;
            var marginHeight = FlexibleMaterialForm.Height - FlexibleMaterialForm.richTextBoxMessage.Height;

            //Set calculated dialog size (if the calculated values exceed the maximums, they were cut by windows forms automatically)
            FlexibleMaterialForm.Size = new Size(textWidth + marginWidth,
                                                 textHeight + marginHeight);
        }
        /// <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 FlexibleMaterialForm = new FlexibleMaterialForm();

            FlexibleMaterialForm.ShowInTaskbar = false;

            //Bind the caption and the message text
            FlexibleMaterialForm.CaptionText = caption;
            FlexibleMaterialForm.MessageText = text;
            FlexibleMaterialForm.FlexibleMaterialFormBindingSource.DataSource = FlexibleMaterialForm;

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

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

            //Set the font for all controls
            FlexibleMaterialForm.Font = FONT;
            FlexibleMaterialForm.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(FlexibleMaterialForm, text, caption);

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

            //Show the dialog
            return(FlexibleMaterialForm.ShowDialog(owner));
        }
Esempio n. 3
0
        /// <summary>
        /// Set the dialogs icon.
        /// When no icon is used: Correct placement and width of rich text box.
        /// </summary>
        /// <param name="FlexibleMaterialForm">The FlexibleMessageBox dialog.</param>
        /// <param name="icon">The MessageBoxIcon.</param>
        private static void SetDialogIcon(FlexibleMaterialForm FlexibleMaterialForm, MessageBoxIcon icon)
        {
            switch (icon)
            {
            case MessageBoxIcon.Information:
                FlexibleMaterialForm.pictureBoxForIcon.Image = SystemIcons.Information.ToBitmap();
                break;

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

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

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

            default:
                //When no icon is used: Correct placement and width of rich text box.
                FlexibleMaterialForm.pictureBoxForIcon.Visible = false;
                FlexibleMaterialForm.richTextBoxMessage.Left  -= FlexibleMaterialForm.pictureBoxForIcon.Width;
                FlexibleMaterialForm.richTextBoxMessage.Width += FlexibleMaterialForm.pictureBoxForIcon.Width;
                break;
            }
        }
Esempio n. 4
0
 /// <summary>
 /// Set the dialogs start position when given.
 /// Otherwise center the dialog on the current screen.
 /// </summary>
 /// <param name="FlexibleMaterialForm">The FlexibleMessageBox dialog.</param>
 /// <param name="owner">The owner.</param>
 private static void SetDialogStartPosition(FlexibleMaterialForm FlexibleMaterialForm, IWin32Window owner)
 {
     //If no owner given: Center on current screen
     if (owner == null)
     {
         var screen = Screen.FromPoint(Cursor.Position);
         FlexibleMaterialForm.StartPosition = FormStartPosition.Manual;
         FlexibleMaterialForm.Left          = screen.Bounds.Left + screen.Bounds.Width / 2 - FlexibleMaterialForm.Width / 2;
         FlexibleMaterialForm.Top           = screen.Bounds.Top + screen.Bounds.Height / 2 - FlexibleMaterialForm.Height / 2;
     }
 }
 public static DialogResult Show(IWin32Window owner, string text, string caption, MessageBoxButtons buttons, MessageBoxIcon icon, MessageBoxDefaultButton defaultButton)
 {
     return(FlexibleMaterialForm.Show(owner, text, caption, buttons, icon, defaultButton));
 }
 public static DialogResult Show(string text, string caption, MessageBoxButtons buttons, MessageBoxIcon icon)
 {
     return(FlexibleMaterialForm.Show(null, text, caption, buttons, icon, MessageBoxDefaultButton.Button1));
 }
 public static DialogResult Show(IWin32Window owner, string text, string caption)
 {
     return(FlexibleMaterialForm.Show(owner, text, caption, MessageBoxButtons.OK, MessageBoxIcon.None, MessageBoxDefaultButton.Button1));
 }
 public static DialogResult Show(string text)
 {
     return(FlexibleMaterialForm.Show(null, text, string.Empty, MessageBoxButtons.OK, MessageBoxIcon.None, MessageBoxDefaultButton.Button1));
 }
Esempio n. 9
0
 public static DialogResult Show(string text, string caption, MessageBoxButtons messageBoxButtons, FlexibleMaterialForm.ButtonsPosition buttonsPosition = FlexibleMaterialForm.ButtonsPosition.Right)
 {
     return(FlexibleMaterialForm.Show(null, text, caption, messageBoxButtons, MessageBoxIcon.None, MessageBoxDefaultButton.Button1, true, buttonsPosition));
 }
 public static DialogResult Show(string text, string caption, MessageBoxButtons buttons, MessageBoxIcon icon, MessageBoxDefaultButton defaultButton, bool UseRichTextBox = true)
 {
     return(FlexibleMaterialForm.Show(null, text, caption, buttons, icon, defaultButton, UseRichTextBox));
 }
Esempio n. 11
0
        /// <summary>
        /// Set dialog buttons visibilities and texts.
        /// Also set a default button.
        /// </summary>
        /// <param name="FlexibleMaterialForm">The FlexibleMessageBox dialog.</param>
        /// <param name="buttons">The buttons.</param>
        /// <param name="defaultButton">The default button.</param>
        private static void SetDialogButtons(FlexibleMaterialForm FlexibleMaterialForm, MessageBoxButtons buttons, MessageBoxDefaultButton defaultButton, ButtonsPosition buttonsPosition)
        {
            //Set the buttons visibilities and texts
            switch (buttons)
            {
            case MessageBoxButtons.AbortRetryIgnore:
                FlexibleMaterialForm.visibleButtonsCount = 3;

                FlexibleMaterialForm.leftButton.Visible      = true;
                FlexibleMaterialForm.leftButton.Text         = FlexibleMaterialForm.GetButtonText(ButtonID.ABORT);
                FlexibleMaterialForm.leftButton.DialogResult = DialogResult.Abort;

                FlexibleMaterialForm.middleButton.Visible      = true;
                FlexibleMaterialForm.middleButton.Text         = FlexibleMaterialForm.GetButtonText(ButtonID.RETRY);
                FlexibleMaterialForm.middleButton.DialogResult = DialogResult.Retry;

                FlexibleMaterialForm.rightButton.Visible      = true;
                FlexibleMaterialForm.rightButton.Text         = FlexibleMaterialForm.GetButtonText(ButtonID.IGNORE);
                FlexibleMaterialForm.rightButton.DialogResult = DialogResult.Ignore;

                FlexibleMaterialForm.ControlBox = false;
                break;

            case MessageBoxButtons.OKCancel:
                FlexibleMaterialForm.visibleButtonsCount = 2;

                FlexibleMaterialForm.middleButton.Visible      = true;
                FlexibleMaterialForm.middleButton.Text         = FlexibleMaterialForm.GetButtonText(ButtonID.CANCEL);
                FlexibleMaterialForm.middleButton.DialogResult = DialogResult.Cancel;

                FlexibleMaterialForm.rightButton.Visible      = true;
                FlexibleMaterialForm.rightButton.Text         = FlexibleMaterialForm.GetButtonText(ButtonID.OK);
                FlexibleMaterialForm.rightButton.DialogResult = DialogResult.OK;

                FlexibleMaterialForm.CancelButton = FlexibleMaterialForm.middleButton;
                break;

            case MessageBoxButtons.RetryCancel:
                FlexibleMaterialForm.visibleButtonsCount = 2;

                FlexibleMaterialForm.middleButton.Visible      = true;
                FlexibleMaterialForm.middleButton.Text         = FlexibleMaterialForm.GetButtonText(ButtonID.CANCEL);
                FlexibleMaterialForm.middleButton.DialogResult = DialogResult.Cancel;

                FlexibleMaterialForm.rightButton.Visible      = true;
                FlexibleMaterialForm.rightButton.Text         = FlexibleMaterialForm.GetButtonText(ButtonID.RETRY);
                FlexibleMaterialForm.rightButton.DialogResult = DialogResult.Retry;

                FlexibleMaterialForm.CancelButton = FlexibleMaterialForm.middleButton;
                break;

            case MessageBoxButtons.YesNo:
                FlexibleMaterialForm.visibleButtonsCount = 2;

                FlexibleMaterialForm.middleButton.Visible      = true;
                FlexibleMaterialForm.middleButton.Text         = FlexibleMaterialForm.GetButtonText(ButtonID.NO);
                FlexibleMaterialForm.middleButton.DialogResult = DialogResult.No;

                FlexibleMaterialForm.rightButton.Visible      = true;
                FlexibleMaterialForm.rightButton.Text         = FlexibleMaterialForm.GetButtonText(ButtonID.YES);
                FlexibleMaterialForm.rightButton.DialogResult = DialogResult.Yes;

                //FlexibleMaterialForm.ControlBox = false;
                break;

            case MessageBoxButtons.YesNoCancel:
                FlexibleMaterialForm.visibleButtonsCount = 3;

                FlexibleMaterialForm.rightButton.Visible      = true;
                FlexibleMaterialForm.rightButton.Text         = FlexibleMaterialForm.GetButtonText(ButtonID.YES);
                FlexibleMaterialForm.rightButton.DialogResult = DialogResult.Yes;

                FlexibleMaterialForm.middleButton.Visible      = true;
                FlexibleMaterialForm.middleButton.Text         = FlexibleMaterialForm.GetButtonText(ButtonID.NO);
                FlexibleMaterialForm.middleButton.DialogResult = DialogResult.No;

                FlexibleMaterialForm.leftButton.Visible      = true;
                FlexibleMaterialForm.leftButton.Text         = FlexibleMaterialForm.GetButtonText(ButtonID.CANCEL);
                FlexibleMaterialForm.leftButton.DialogResult = DialogResult.Cancel;

                FlexibleMaterialForm.CancelButton = FlexibleMaterialForm.leftButton;
                break;

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

                FlexibleMaterialForm.CancelButton = FlexibleMaterialForm.rightButton;
                break;
            }

            //Set default button (used in FlexibleMaterialForm_Shown)
            FlexibleMaterialForm.defaultButton = defaultButton;

            SetButtonsPosition(FlexibleMaterialForm, buttonsPosition);
        }
Esempio n. 12
0
 public static DialogResult Show(IWin32Window owner, string text, bool UseRichTextBox = true, FlexibleMaterialForm.ButtonsPosition buttonsPosition = FlexibleMaterialForm.ButtonsPosition.Right)
 {
     return(FlexibleMaterialForm.Show(owner, text, string.Empty, MessageBoxButtons.OK, MessageBoxIcon.None, MessageBoxDefaultButton.Button1, UseRichTextBox, buttonsPosition));
 }
Esempio n. 13
0
 public static DialogResult Show(string text, string caption, MessageBoxButtons buttons, MessageBoxIcon icon, MessageBoxDefaultButton defaultButton, bool UseRichTextBox = true, FlexibleMaterialForm.ButtonsPosition buttonsPosition = FlexibleMaterialForm.ButtonsPosition.Right, RightToLeft RightToLeft = RightToLeft.No)
 {
     return(FlexibleMaterialForm.Show(null, text, caption, buttons, icon, defaultButton, UseRichTextBox, buttonsPosition, RightToLeft));
 }
Esempio n. 14
0
 public static DialogResult Show(IWin32Window owner, string text, string caption, MessageBoxButtons buttons, bool UseRichTextBox = true, FlexibleMaterialForm.ButtonsPosition buttonsPosition = FlexibleMaterialForm.ButtonsPosition.Right, RightToLeft RightToLeft = RightToLeft.No)
 {
     return(FlexibleMaterialForm.Show(owner, text, caption, buttons, MessageBoxIcon.None, MessageBoxDefaultButton.Button1, UseRichTextBox, buttonsPosition, RightToLeft));
 }
Esempio n. 15
0
 public static DialogResult Show(string text, bool UseRichTextBox = true, FlexibleMaterialForm.ButtonsPosition buttonsPosition = FlexibleMaterialForm.ButtonsPosition.Right, RightToLeft RightToLeft = RightToLeft.No)
 {
     return(FlexibleMaterialForm.Show(null, text, string.Empty, MessageBoxButtons.OK, MessageBoxIcon.None, MessageBoxDefaultButton.Button1, UseRichTextBox, buttonsPosition, RightToLeft));
 }
Esempio n. 16
0
 public static DialogResult Show(string text, string caption, bool UseRichTextBox = true, FlexibleMaterialForm.ButtonsPosition buttonsPosition = FlexibleMaterialForm.ButtonsPosition.Right)
 {
     return(FlexibleMaterialForm.Show(null, text, caption, MessageBoxButtons.OK, MessageBoxIcon.None, MessageBoxDefaultButton.Button1, UseRichTextBox, buttonsPosition));
 }
Esempio n. 17
0
 public static DialogResult Show(IWin32Window owner, string text, string caption, MessageBoxButtons buttons, MessageBoxIcon icon, MessageBoxDefaultButton defaultButton, bool UseRichTextBox = true, FlexibleMaterialForm.ButtonsPosition buttonsPosition = FlexibleMaterialForm.ButtonsPosition.Right)
 {
     return(FlexibleMaterialForm.Show(owner, text, caption, buttons, icon, defaultButton, UseRichTextBox, buttonsPosition));
 }
Esempio n. 18
0
        private static void SetButtonsPosition(FlexibleMaterialForm fMF, ButtonsPosition buttonsPosition)
        {
            const int padding             = 10;
            int       visibleButtonsWidth = 0;

            switch (buttonsPosition)
            {
            case ButtonsPosition.Center:
                switch (fMF.visibleButtonsCount)
                {
                case 3:
                    fMF.middleButton.Left = fMF.Width / 2 - fMF.middleButton.Width / 2;
                    fMF.leftButton.Left   = fMF.middleButton.Left - fMF.leftButton.Width - padding * 2;
                    fMF.rightButton.Left  = fMF.middleButton.Right + padding * 2;
                    visibleButtonsWidth   = fMF.leftButton.Width + fMF.middleButton.Width + fMF.rightButton.Width + padding * 6;
                    break;

                case 2:
                    fMF.middleButton.Left = fMF.Width / 2 - fMF.middleButton.Width - padding;
                    fMF.rightButton.Left  = fMF.Width / 2 + padding;
                    visibleButtonsWidth   = fMF.middleButton.Width + fMF.rightButton.Width + padding * 4;
                    break;

                case 1:
                    fMF.rightButton.Left = fMF.Width / 2 - fMF.rightButton.Width / 2;
                    visibleButtonsWidth  = fMF.rightButton.Width + padding * 2;
                    break;

                default:
                    break;
                }
                break;

            case ButtonsPosition.Left:
                switch (fMF.visibleButtonsCount)
                {
                case 3:
                    fMF.leftButton.Left   = padding;
                    fMF.middleButton.Left = fMF.leftButton.Right + padding * 2;
                    fMF.rightButton.Left  = fMF.middleButton.Right + padding * 2;
                    visibleButtonsWidth   = fMF.leftButton.Width + fMF.middleButton.Width + fMF.rightButton.Width + padding * 6;
                    break;

                case 2:
                    fMF.middleButton.Left = padding;
                    fMF.rightButton.Left  = fMF.middleButton.Right + padding * 2;
                    visibleButtonsWidth   = fMF.middleButton.Width + fMF.rightButton.Width + padding * 4;
                    break;

                case 1:
                    fMF.rightButton.Left = padding;
                    visibleButtonsWidth  = fMF.rightButton.Width + padding * 2;
                    break;

                default:
                    break;
                }
                break;

            case ButtonsPosition.Right:
                // This alignment is simplest, in this alignment doesn't care how many buttons are visible.
                // Always the buttons visibility order is right, right + middle, right + middle + left
                fMF.rightButton.Left  = fMF.Width - fMF.rightButton.Width - padding;
                fMF.middleButton.Left = fMF.rightButton.Left - fMF.middleButton.Width - padding * 2;
                fMF.leftButton.Left   = fMF.middleButton.Left - fMF.leftButton.Width - padding * 2;
                switch (fMF.visibleButtonsCount)
                {
                case 3:
                    visibleButtonsWidth = fMF.leftButton.Width + fMF.middleButton.Width + fMF.rightButton.Width + padding * 6;
                    break;

                case 2:
                    visibleButtonsWidth = fMF.middleButton.Width + fMF.rightButton.Width + padding * 4;
                    break;

                case 1:
                    visibleButtonsWidth = fMF.rightButton.Width + padding * 2;
                    break;

                default:
                    break;
                }
                break;

            case ButtonsPosition.Fill:
                switch (fMF.visibleButtonsCount)
                {
                case 3:
                    fMF.leftButton.Left   = padding;
                    fMF.middleButton.Left = fMF.Width / 2 - fMF.middleButton.Width / 2;
                    fMF.rightButton.Left  = fMF.Width - fMF.rightButton.Width - padding * 2;
                    visibleButtonsWidth   = fMF.leftButton.Width + fMF.middleButton.Width + fMF.rightButton.Width + padding * 6;
                    break;

                case 2:
                    fMF.middleButton.Left = padding;
                    fMF.rightButton.Left  = fMF.Width - fMF.rightButton.Width - padding * 2;
                    visibleButtonsWidth   = fMF.middleButton.Width + fMF.rightButton.Width + padding * 4;
                    break;

                case 1:
                    fMF.rightButton.Left = fMF.Width / 2 - fMF.middleButton.Width / 2;
                    visibleButtonsWidth  = fMF.rightButton.Width + padding * 2;
                    break;

                default:
                    break;
                }
                break;
            }
            fMF.Width = Math.Max(fMF.Width, visibleButtonsWidth);
        }
 public static DialogResult Show(IWin32Window owner, string text, string caption, MessageBoxButtons buttons, bool UseRichTextBox = true)
 {
     return(FlexibleMaterialForm.Show(owner, text, caption, buttons, MessageBoxIcon.None, MessageBoxDefaultButton.Button1, UseRichTextBox));
 }