Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 23 additions & 3 deletions InfoBox.Designer/CodeGeneration/CSharpGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -224,10 +224,30 @@ public string GenerateSingleCall(InformationBoxBehavior behavior,
codeBuilder.AppendFormat(CultureInfo.InvariantCulture, "design: new DesignParameters(System.Drawing.Color.FromArgb({0},{1},{2}), System.Drawing.Color.FromArgb({3},{4},{5})), ", design.FormBackColor.R, design.FormBackColor.G, design.FormBackColor.B, design.BarsBackColor.R, design.BarsBackColor.G, design.BarsBackColor.B);
}

if (null != fontParameters && fontParameters.MessageFont != null)
if (null != fontParameters && fontParameters.IsSet())
{
codeBuilder.AppendFormat(CultureInfo.InvariantCulture, "fontParameters: new FontParameters(new System.Drawing.Font(\"{0}\", {1}F)), ",
fontParameters.MessageFont.Name, fontParameters.MessageFont.Size);
var color = string.Empty;
var font = "null";

if (fontParameters.HasFont())
{
font = string.Format(CultureInfo.InvariantCulture,
"new System.Drawing.Font(\"{0}\", {1}F)",
fontParameters.MessageFont.Name,
fontParameters.MessageFont.Size);
}

if (fontParameters.HasColor())
{
color = string.Format(CultureInfo.InvariantCulture,
", System.Drawing.Color.FromArgb({0},{1},{2})",
fontParameters.MessageColor.Value.R,
fontParameters.MessageColor.Value.G,
fontParameters.MessageColor.Value.B);
}

codeBuilder.AppendFormat(CultureInfo.InvariantCulture,
"fontParameters: new FontParameters({0}{1}), ", font, color);
}

if (titleStyle == InformationBoxTitleIconStyle.Custom)
Expand Down
26 changes: 23 additions & 3 deletions InfoBox.Designer/CodeGeneration/VbNetGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -192,10 +192,30 @@ public string GenerateSingleCall(InformationBoxBehavior behavior, string text, s
codeBuilder.AppendFormat(CultureInfo.InvariantCulture, "New DesignParameters(Color.FromArgb({0},{1},{2}), Color.FromArgb({3},{4},{5})), ", design.FormBackColor.R, design.FormBackColor.G, design.FormBackColor.B, design.BarsBackColor.R, design.BarsBackColor.G, design.BarsBackColor.B);
}

if (null != fontParameters && fontParameters.MessageFont != null)
if (null != fontParameters && fontParameters.IsSet())
{
codeBuilder.AppendFormat(CultureInfo.InvariantCulture, "New FontParameters(New Font(\"{0}\", {1}F)), ",
fontParameters.MessageFont.Name, fontParameters.MessageFont.Size);
var color = string.Empty;
var font = "Nothing";

if (fontParameters.HasFont())
{
font = string.Format(CultureInfo.InvariantCulture,
"New Font(\"{0}\", {1}F)",
fontParameters.MessageFont.Name,
fontParameters.MessageFont.Size);
}

if (fontParameters.HasColor())
{
color = string.Format(CultureInfo.InvariantCulture,
", Color.FromArgb({0},{1},{2})",
fontParameters.MessageColor.Value.R,
fontParameters.MessageColor.Value.G,
fontParameters.MessageColor.Value.B);
}

codeBuilder.AppendFormat(CultureInfo.InvariantCulture,
"New FontParameters({0}{1}), ", font, color);
}

if (titleStyle == InformationBoxTitleIconStyle.Custom)
Expand Down
51 changes: 50 additions & 1 deletion InfoBox.Designer/InformationBoxDesigner.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

41 changes: 39 additions & 2 deletions InfoBox.Designer/InformationBoxDesigner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ public partial class InformationBoxDesigner : Form
/// </summary>
private Font messageFont = null;

/// <summary>
/// Color for the message text
/// </summary>
private Color messageFontColor = Color.Empty;

#endregion Attributes

#region Constructors
Expand Down Expand Up @@ -196,6 +201,9 @@ private void LoadBindings()
this.lblMessageFont.DataBindings.Add("Enabled", this.chbCustomFonts, "Checked");
this.txbMessageFont.DataBindings.Add("Enabled", this.chbCustomFonts, "Checked");
this.btnMessageFont.DataBindings.Add("Enabled", this.chbCustomFonts, "Checked");
this.lblMessageColor.DataBindings.Add("Enabled", this.chbCustomFonts, "Checked");
this.txbMessageColor.DataBindings.Add("Enabled", this.chbCustomFonts, "Checked");
this.btnMessageColor.DataBindings.Add("Enabled", this.chbCustomFonts, "Checked");
}

#endregion Loading
Expand Down Expand Up @@ -549,12 +557,12 @@ private DesignParameters GetDesign()
/// <returns>The font parameters.</returns>
private FontParameters GetFontParameters()
{
if (!this.chbCustomFonts.Checked || this.messageFont == null)
if (!this.chbCustomFonts.Checked)
{
return null;
}

return new FontParameters(this.messageFont);
return new FontParameters(this.messageFont, this.messageFontColor);
}

/// <summary>
Expand Down Expand Up @@ -813,6 +821,8 @@ private void BtnMessageFont_Click(object sender, EventArgs e)

if (this.dlgFont.ShowDialog() != DialogResult.OK)
{
this.messageFont = null;
this.txbMessageFont.Text = string.Empty;
return;
}

Expand All @@ -822,6 +832,33 @@ private void BtnMessageFont_Click(object sender, EventArgs e)
this.messageFont = selected;
}

/// <summary>
/// Handles the Click event of the BtnMessageColor control.
/// </summary>
/// <param name="sender">The source of the event.</param>
/// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
private void BtnMessageColor_Click(object sender, EventArgs e)
{
if (this.messageFontColor != Color.Empty)
{
this.dlgColor.Color = this.messageFontColor;
}

if (this.dlgColor.ShowDialog() != DialogResult.OK)
{
this.txbMessageColor.Text = string.Empty;
this.lblFontColor.BackColor = SystemColors.Control;
this.messageFontColor = Color.Empty;
return;
}

Color selected = this.dlgColor.Color;

this.txbMessageColor.Text = string.Format("R={0}, G={1}, B={2}", selected.R, selected.G, selected.B);
this.lblFontColor.BackColor = selected;
this.messageFontColor = selected;
}

#endregion Fonts

#endregion Event handlers
Expand Down
12 changes: 10 additions & 2 deletions InfoBox/Form/InformationBoxForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1244,9 +1244,17 @@ private void SetOrder()
/// </summary>
private void SetFont()
{
if (this.fontParameters != null && this.fontParameters.MessageFont != null)
if (this.fontParameters != null)
{
this.messageText.Font = this.fontParameters.MessageFont;
if (this.fontParameters.HasFont())
{
this.messageText.Font = this.fontParameters.MessageFont;
}

if (this.fontParameters.HasColor())
{
this.messageText.ForeColor = this.fontParameters.MessageColor.Value;
}
}
}

Expand Down
55 changes: 53 additions & 2 deletions InfoBox/Parameters/FontParameters.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,18 @@ public class FontParameters
public FontParameters(Font messageFont)
{
this.MessageFont = messageFont;
this.MessageColor = null;
}

/// <summary>
/// Initializes a new instance of the <see cref="FontParameters"/> class.
/// </summary>
/// <param name="messageFont">The font to use for message text.</param>
/// <param name="messageColor">The color to use for message text.</param>
public FontParameters(Font messageFont, Color messageColor)
{
this.MessageFont = messageFont;
this.MessageColor = messageColor;
}

#endregion Constructors
Expand All @@ -34,8 +46,45 @@ public FontParameters(Font messageFont)
/// <value>The font for the message text.</value>
public Font MessageFont { get; private set; }

/// <summary>
/// Gets the color for the message text.
/// </summary>
/// <value>The color for the message text, or null to use the system default.</value>
public Color? MessageColor { get; private set; }

#endregion Properties

#region Methods

/// <summary>
/// Determines whether the current instance has either a font or a color defined.
/// </summary>
/// <returns>true if the instance has either a font or a color defined; otherwise, false.</returns>
public bool IsSet()
{
return this.HasFont() || this.HasColor();
}

/// <summary>
/// Determines whether the current instance has a font defined.
/// </summary>
/// <returns>true if the instance has a font defined; otherwise, false.</returns>
public bool HasFont()
{
return this.MessageFont != null;
}

/// <summary>
/// Determines whether the current instance has a color defined.
/// </summary>
/// <returns>true if the instance has a color defined; otherwise, false.</returns>
public bool HasColor()
{
return this.MessageColor.HasValue && this.MessageColor != Color.Empty;
}

#endregion

#region Overrides

/// <summary>
Expand All @@ -55,7 +104,8 @@ public override bool Equals(object obj)

FontParameters compared = (FontParameters)obj;

return object.Equals(this.MessageFont, compared.MessageFont);
return object.Equals(this.MessageFont, compared.MessageFont) &&
this.MessageColor == compared.MessageColor;
}

/// <summary>
Expand All @@ -66,7 +116,8 @@ public override bool Equals(object obj)
/// </returns>
public override int GetHashCode()
{
return this.MessageFont?.GetHashCode() ?? 0;
return (this.MessageFont?.GetHashCode() ?? 0) ^
(this.MessageColor?.GetHashCode() ?? 0);
}

#endregion Overrides
Expand Down
Loading
Loading