Skip to content

Commit

Permalink
Merge pull request #161 from orapps44/patch-7
Browse files Browse the repository at this point in the history
Fix MaterialMessageBox Icons cut off & missing caption when Buttons are "YesNo"
  • Loading branch information
leocb authored May 7, 2021
2 parents 3a993f6 + 7c7723b commit 11bbb96
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 34 deletions.
63 changes: 50 additions & 13 deletions MaterialSkin/Controls/FlexibleMaterialDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public class FlexibleMaterialForm : MaterialForm, IMaterialControl
public static double MAX_HEIGHT_FACTOR = 0.9;

private MaterialMultiLineTextBox richTextBoxMessage;
private MaterialLabel materialLabel1;

/// <summary>
/// Erforderliche Designervariable.
Expand Down Expand Up @@ -74,6 +75,7 @@ private void InitializeComponent()
this.leftButton = new MaterialSkin.Controls.MaterialButton();
this.FlexibleMaterialFormBindingSource = new System.Windows.Forms.BindingSource(this.components);
this.messageContainer = new System.Windows.Forms.Panel();
this.materialLabel1 = new MaterialSkin.Controls.MaterialLabel();
this.pictureBoxForIcon = new System.Windows.Forms.PictureBox();
this.richTextBoxMessage = new MaterialSkin.Controls.MaterialMultiLineTextBox();
this.middleButton = new MaterialSkin.Controls.MaterialButton();
Expand All @@ -93,7 +95,7 @@ private void InitializeComponent()
this.leftButton.DrawShadows = true;
this.leftButton.HighEmphasis = false;
this.leftButton.Icon = null;
this.leftButton.Location = new System.Drawing.Point(44, 163);
this.leftButton.Location = new System.Drawing.Point(40, 163);
this.leftButton.Margin = new System.Windows.Forms.Padding(4, 6, 4, 6);
this.leftButton.MinimumSize = new System.Drawing.Size(0, 24);
this.leftButton.MouseState = MaterialSkin.MouseState.HOVER;
Expand All @@ -112,17 +114,34 @@ private void InitializeComponent()
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.messageContainer.BackColor = System.Drawing.Color.White;
this.messageContainer.Controls.Add(this.materialLabel1);
this.messageContainer.Controls.Add(this.pictureBoxForIcon);
this.messageContainer.Controls.Add(this.richTextBoxMessage);
this.messageContainer.Location = new System.Drawing.Point(0, 65);
this.messageContainer.Location = new System.Drawing.Point(1, 65);
this.messageContainer.Name = "messageContainer";
this.messageContainer.Size = new System.Drawing.Size(388, 81);
this.messageContainer.Size = new System.Drawing.Size(382, 89);
this.messageContainer.TabIndex = 1;
//
// materialLabel1
//
this.materialLabel1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.materialLabel1.DataBindings.Add(new System.Windows.Forms.Binding("Text", this.FlexibleMaterialFormBindingSource, "MessageText", true, System.Windows.Forms.DataSourceUpdateMode.OnPropertyChanged));
this.materialLabel1.Depth = 0;
this.materialLabel1.Font = new System.Drawing.Font("Roboto", 14F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Pixel);
this.materialLabel1.Location = new System.Drawing.Point(56, 12);
this.materialLabel1.MouseState = MaterialSkin.MouseState.HOVER;
this.materialLabel1.Name = "materialLabel1";
this.materialLabel1.Size = new System.Drawing.Size(314, 65);
this.materialLabel1.TabIndex = 9;
this.materialLabel1.Text = "<Message>";
this.materialLabel1.Visible = false;
//
// pictureBoxForIcon
//
this.pictureBoxForIcon.BackColor = System.Drawing.Color.Transparent;
this.pictureBoxForIcon.Location = new System.Drawing.Point(15, 19);
this.pictureBoxForIcon.Location = new System.Drawing.Point(12, 12);
this.pictureBoxForIcon.Name = "pictureBoxForIcon";
this.pictureBoxForIcon.Size = new System.Drawing.Size(32, 32);
this.pictureBoxForIcon.TabIndex = 8;
Expand All @@ -140,13 +159,13 @@ private void InitializeComponent()
this.richTextBoxMessage.Font = new System.Drawing.Font("Microsoft Sans Serif", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.richTextBoxMessage.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(180)))), ((int)(((byte)(0)))), ((int)(((byte)(0)))), ((int)(((byte)(0)))));
this.richTextBoxMessage.Hint = "";
this.richTextBoxMessage.Location = new System.Drawing.Point(47, 2);
this.richTextBoxMessage.Location = new System.Drawing.Point(56, 12);
this.richTextBoxMessage.Margin = new System.Windows.Forms.Padding(0);
this.richTextBoxMessage.MouseState = MaterialSkin.MouseState.HOVER;
this.richTextBoxMessage.Name = "richTextBoxMessage";
this.richTextBoxMessage.ReadOnly = true;
this.richTextBoxMessage.ScrollBars = System.Windows.Forms.RichTextBoxScrollBars.Vertical;
this.richTextBoxMessage.Size = new System.Drawing.Size(338, 78);
this.richTextBoxMessage.Size = new System.Drawing.Size(314, 65);
this.richTextBoxMessage.TabIndex = 0;
this.richTextBoxMessage.TabStop = false;
this.richTextBoxMessage.Text = "<Message>";
Expand All @@ -162,7 +181,7 @@ private void InitializeComponent()
this.middleButton.DrawShadows = true;
this.middleButton.HighEmphasis = true;
this.middleButton.Icon = null;
this.middleButton.Location = new System.Drawing.Point(160, 163);
this.middleButton.Location = new System.Drawing.Point(156, 163);
this.middleButton.Margin = new System.Windows.Forms.Padding(4, 6, 4, 6);
this.middleButton.MinimumSize = new System.Drawing.Size(0, 24);
this.middleButton.MouseState = MaterialSkin.MouseState.HOVER;
Expand All @@ -185,7 +204,7 @@ private void InitializeComponent()
this.rightButton.DrawShadows = true;
this.rightButton.HighEmphasis = true;
this.rightButton.Icon = null;
this.rightButton.Location = new System.Drawing.Point(270, 163);
this.rightButton.Location = new System.Drawing.Point(266, 163);
this.rightButton.Margin = new System.Windows.Forms.Padding(4, 6, 4, 6);
this.rightButton.MinimumSize = new System.Drawing.Size(0, 24);
this.rightButton.MouseState = MaterialSkin.MouseState.HOVER;
Expand All @@ -201,7 +220,7 @@ private void InitializeComponent()
// FlexibleMaterialForm
//
this.BackColor = System.Drawing.Color.White;
this.ClientSize = new System.Drawing.Size(388, 208);
this.ClientSize = new System.Drawing.Size(384, 208);
this.Controls.Add(this.rightButton);
this.Controls.Add(this.middleButton);
this.Controls.Add(this.messageContainer);
Expand Down Expand Up @@ -313,7 +332,12 @@ private enum TwoLetterISOLanguageID
/// <summary>
/// Defines the it
/// </summary>
it
it,

/// <summary>
/// Defines the fr
/// </summary>
fr
};

/// <summary>
Expand All @@ -336,6 +360,11 @@ private enum TwoLetterISOLanguageID
/// </summary>
private static readonly String[] BUTTON_TEXTS_ITALIAN_IT = { "OK", "Annulla", "&Sì", "&No", "&Interrompi", "&Riprova", "&Ignora" };

/// <summary>
/// Defines the BUTTON_TEXTS_ENGLISH_FR
/// </summary>
private static readonly String[] BUTTON_TEXTS_FRENCH_FR = { "OK", "Annuler", "&Oui", "&Non", "&Interrompre", "&Recommencer", "&Ignorer" };

/// <summary>
/// Defines the defaultButton
/// </summary>
Expand Down Expand Up @@ -400,6 +429,7 @@ private string GetButtonText(ButtonID buttonID)
case TwoLetterISOLanguageID.de: return BUTTON_TEXTS_GERMAN_DE[buttonTextArrayIndex];
case TwoLetterISOLanguageID.es: return BUTTON_TEXTS_SPANISH_ES[buttonTextArrayIndex];
case TwoLetterISOLanguageID.it: return BUTTON_TEXTS_ITALIAN_IT[buttonTextArrayIndex];
case TwoLetterISOLanguageID.fr: return BUTTON_TEXTS_FRENCH_FR[buttonTextArrayIndex];

default: return BUTTON_TEXTS_ENGLISH_EN[buttonTextArrayIndex];
}
Expand Down Expand Up @@ -482,6 +512,9 @@ private static void SetDialogSizes(FlexibleMaterialForm FlexibleMaterialForm, st
var marginWidth = FlexibleMaterialForm.Width - FlexibleMaterialForm.richTextBoxMessage.Width;
var marginHeight = FlexibleMaterialForm.Height - FlexibleMaterialForm.richTextBoxMessage.Height;

var minimumHeight = FlexibleMaterialForm.messageContainer.Top + (FlexibleMaterialForm.pictureBoxForIcon.Height + 2 * 8) + 54;
if (marginHeight < minimumHeight) marginHeight = minimumHeight;

//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);
Expand Down Expand Up @@ -591,7 +624,7 @@ private static void SetDialogButtons(FlexibleMaterialForm FlexibleMaterialForm,
FlexibleMaterialForm.rightButton.Text = FlexibleMaterialForm.GetButtonText(ButtonID.YES);
FlexibleMaterialForm.rightButton.DialogResult = DialogResult.Yes;

FlexibleMaterialForm.ControlBox = false;
//FlexibleMaterialForm.ControlBox = false;
break;

case MessageBoxButtons.YesNoCancel:
Expand Down Expand Up @@ -748,11 +781,12 @@ internal void FlexibleMaterialForm_KeyUp(object sender, KeyEventArgs e)
/// <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)
public static DialogResult Show(IWin32Window owner, string text, string caption, MessageBoxButtons buttons, MessageBoxIcon icon, MessageBoxDefaultButton defaultButton, bool UseRichTextBox = true)
{
//Create a new instance of the FlexibleMessageBox form
var FlexibleMaterialForm = new FlexibleMaterialForm();
FlexibleMaterialForm.ShowInTaskbar = false;
FlexibleMaterialForm.Sizable = false;

//Bind the caption and the message text
FlexibleMaterialForm.CaptionText = caption;
Expand All @@ -768,6 +802,9 @@ public static DialogResult Show(IWin32Window owner, string text, string caption,
//Set the font for all controls
FlexibleMaterialForm.Font = FONT;
FlexibleMaterialForm.richTextBoxMessage.Font = FONT;
FlexibleMaterialForm.richTextBoxMessage.Visible = UseRichTextBox;
FlexibleMaterialForm.materialLabel1.Font = FONT;
FlexibleMaterialForm.materialLabel1.Visible = !UseRichTextBox;

//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);
Expand All @@ -783,4 +820,4 @@ private void FlexibleMaterialForm_Load(object sender, EventArgs e)
{
}
}
}
}
42 changes: 21 additions & 21 deletions MaterialSkin/Controls/MaterialMessageBox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,54 +21,54 @@ public class MaterialMessageBox : IMaterialControl
[Browsable(false)]
public Point MouseLocation { get; set; }

public static DialogResult Show(string text)
public static DialogResult Show(string text, bool UseRichTextBox = true)
{
return FlexibleMaterialForm.Show(null, text, string.Empty, MessageBoxButtons.OK, MessageBoxIcon.None, MessageBoxDefaultButton.Button1);
return FlexibleMaterialForm.Show(null, text, string.Empty, MessageBoxButtons.OK, MessageBoxIcon.None, MessageBoxDefaultButton.Button1, UseRichTextBox);
}

public static DialogResult Show(IWin32Window owner, string text)
public static DialogResult Show(IWin32Window owner, string text, bool UseRichTextBox = true)
{
return FlexibleMaterialForm.Show(owner, text, string.Empty, MessageBoxButtons.OK, MessageBoxIcon.None, MessageBoxDefaultButton.Button1);
return FlexibleMaterialForm.Show(owner, text, string.Empty, MessageBoxButtons.OK, MessageBoxIcon.None, MessageBoxDefaultButton.Button1, UseRichTextBox);
}

public static DialogResult Show(string text, string caption)
public static DialogResult Show(string text, string caption, bool UseRichTextBox = true)
{
return FlexibleMaterialForm.Show(null, text, caption, MessageBoxButtons.OK, MessageBoxIcon.None, MessageBoxDefaultButton.Button1);
return FlexibleMaterialForm.Show(null, text, caption, MessageBoxButtons.OK, MessageBoxIcon.None, MessageBoxDefaultButton.Button1, UseRichTextBox);
}

public static DialogResult Show(IWin32Window owner, string text, string caption)
public static DialogResult Show(IWin32Window owner, string text, string caption, bool UseRichTextBox = true)
{
return FlexibleMaterialForm.Show(owner, text, caption, MessageBoxButtons.OK, MessageBoxIcon.None, MessageBoxDefaultButton.Button1);
return FlexibleMaterialForm.Show(owner, text, caption, MessageBoxButtons.OK, MessageBoxIcon.None, MessageBoxDefaultButton.Button1, UseRichTextBox);
}

public static DialogResult Show(string text, string caption, MessageBoxButtons buttons)
public static DialogResult Show(string text, string caption, MessageBoxButtons buttons, bool UseRichTextBox = true)
{
return FlexibleMaterialForm.Show(null, text, caption, buttons, MessageBoxIcon.None, MessageBoxDefaultButton.Button1);
return FlexibleMaterialForm.Show(null, text, caption, buttons, MessageBoxIcon.None, MessageBoxDefaultButton.Button1, UseRichTextBox);
}

public static DialogResult Show(IWin32Window owner, string text, string caption, MessageBoxButtons buttons)
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);
return FlexibleMaterialForm.Show(owner, text, caption, buttons, MessageBoxIcon.None, MessageBoxDefaultButton.Button1, UseRichTextBox);
}

public static DialogResult Show(string text, string caption, MessageBoxButtons buttons, MessageBoxIcon icon)
public static DialogResult Show(string text, string caption, MessageBoxButtons buttons, MessageBoxIcon icon, bool UseRichTextBox = true)
{
return FlexibleMaterialForm.Show(null, text, caption, buttons, icon, MessageBoxDefaultButton.Button1);
return FlexibleMaterialForm.Show(null, text, caption, buttons, icon, MessageBoxDefaultButton.Button1, UseRichTextBox);
}

public static DialogResult Show(IWin32Window owner, string text, string caption, MessageBoxButtons buttons, MessageBoxIcon icon)
public static DialogResult Show(IWin32Window owner, string text, string caption, MessageBoxButtons buttons, MessageBoxIcon icon, bool UseRichTextBox = true)
{
return FlexibleMaterialForm.Show(owner, text, caption, buttons, icon, MessageBoxDefaultButton.Button1);
return FlexibleMaterialForm.Show(owner, text, caption, buttons, icon, MessageBoxDefaultButton.Button1, UseRichTextBox);
}

public static DialogResult Show(string text, string caption, MessageBoxButtons buttons, MessageBoxIcon icon, MessageBoxDefaultButton defaultButton)
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);
return FlexibleMaterialForm.Show(null, text, caption, buttons, icon, defaultButton, UseRichTextBox);
}

public static DialogResult Show(IWin32Window owner, string text, string caption, MessageBoxButtons buttons, MessageBoxIcon icon, MessageBoxDefaultButton defaultButton)
public static DialogResult Show(IWin32Window owner, string text, string caption, MessageBoxButtons buttons, MessageBoxIcon icon, MessageBoxDefaultButton defaultButton, bool UseRichTextBox = true)
{
return FlexibleMaterialForm.Show(owner, text, caption, buttons, icon, defaultButton);
return FlexibleMaterialForm.Show(owner, text, caption, buttons, icon, defaultButton, UseRichTextBox);
}
}
}
}

0 comments on commit 11bbb96

Please sign in to comment.