diff --git a/InfoBox.Designer/CodeGeneration/CSharpGenerator.cs b/InfoBox.Designer/CodeGeneration/CSharpGenerator.cs
index 6b1526a..857ae72 100644
--- a/InfoBox.Designer/CodeGeneration/CSharpGenerator.cs
+++ b/InfoBox.Designer/CodeGeneration/CSharpGenerator.cs
@@ -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)
diff --git a/InfoBox.Designer/CodeGeneration/VbNetGenerator.cs b/InfoBox.Designer/CodeGeneration/VbNetGenerator.cs
index d918076..36e151d 100644
--- a/InfoBox.Designer/CodeGeneration/VbNetGenerator.cs
+++ b/InfoBox.Designer/CodeGeneration/VbNetGenerator.cs
@@ -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)
diff --git a/InfoBox.Designer/InformationBoxDesigner.Designer.cs b/InfoBox.Designer/InformationBoxDesigner.Designer.cs
index eb0415e..e828af7 100644
--- a/InfoBox.Designer/InformationBoxDesigner.Designer.cs
+++ b/InfoBox.Designer/InformationBoxDesigner.Designer.cs
@@ -147,7 +147,11 @@ private void InitializeComponent()
lblMessageFont = new System.Windows.Forms.Label();
txbMessageFont = new System.Windows.Forms.TextBox();
btnMessageFont = new System.Windows.Forms.Button();
+ lblMessageColor = new System.Windows.Forms.Label();
+ txbMessageColor = new System.Windows.Forms.TextBox();
+ btnMessageColor = new System.Windows.Forms.Button();
dlgFont = new System.Windows.Forms.FontDialog();
+ lblFontColor = new System.Windows.Forms.Label();
groupBox1.SuspendLayout();
groupBox2.SuspendLayout();
groupBox3.SuspendLayout();
@@ -1429,15 +1433,19 @@ private void InitializeComponent()
//
// groupBox22
//
+ groupBox22.Controls.Add(lblFontColor);
groupBox22.Controls.Add(chbCustomFonts);
groupBox22.Controls.Add(lblMessageFont);
groupBox22.Controls.Add(txbMessageFont);
groupBox22.Controls.Add(btnMessageFont);
+ groupBox22.Controls.Add(lblMessageColor);
+ groupBox22.Controls.Add(txbMessageColor);
+ groupBox22.Controls.Add(btnMessageColor);
groupBox22.Location = new System.Drawing.Point(14, 546);
groupBox22.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3);
groupBox22.Name = "groupBox22";
groupBox22.Padding = new System.Windows.Forms.Padding(4, 3, 4, 3);
- groupBox22.Size = new System.Drawing.Size(308, 78);
+ groupBox22.Size = new System.Drawing.Size(308, 110);
groupBox22.TabIndex = 25;
groupBox22.TabStop = false;
groupBox22.Text = "Font";
@@ -1483,6 +1491,43 @@ private void InitializeComponent()
btnMessageFont.UseVisualStyleBackColor = true;
btnMessageFont.Click += BtnMessageFont_Click;
//
+ // lblMessageColor
+ //
+ lblMessageColor.AutoSize = true;
+ lblMessageColor.Location = new System.Drawing.Point(8, 78);
+ lblMessageColor.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
+ lblMessageColor.Name = "lblMessageColor";
+ lblMessageColor.Size = new System.Drawing.Size(36, 15);
+ lblMessageColor.TabIndex = 4;
+ lblMessageColor.Text = "Color";
+ //
+ // txbMessageColor
+ //
+ txbMessageColor.Location = new System.Drawing.Point(59, 75);
+ txbMessageColor.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3);
+ txbMessageColor.Name = "txbMessageColor";
+ txbMessageColor.ReadOnly = true;
+ txbMessageColor.Size = new System.Drawing.Size(151, 23);
+ txbMessageColor.TabIndex = 5;
+ //
+ // btnMessageColor
+ //
+ btnMessageColor.Location = new System.Drawing.Point(250, 73);
+ btnMessageColor.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3);
+ btnMessageColor.Name = "btnMessageColor";
+ btnMessageColor.Size = new System.Drawing.Size(29, 25);
+ btnMessageColor.TabIndex = 6;
+ btnMessageColor.Text = "...";
+ btnMessageColor.UseVisualStyleBackColor = true;
+ btnMessageColor.Click += BtnMessageColor_Click;
+ //
+ // lblFontColor
+ //
+ lblFontColor.Location = new System.Drawing.Point(217, 75);
+ lblFontColor.Name = "lblFontColor";
+ lblFontColor.Size = new System.Drawing.Size(24, 23);
+ lblFontColor.TabIndex = 7;
+ //
// InformationBoxDesigner
//
AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
@@ -1687,7 +1732,11 @@ private void InitializeComponent()
private System.Windows.Forms.Label lblMessageFont;
private System.Windows.Forms.TextBox txbMessageFont;
private System.Windows.Forms.Button btnMessageFont;
+ private System.Windows.Forms.Label lblMessageColor;
+ private System.Windows.Forms.TextBox txbMessageColor;
+ private System.Windows.Forms.Button btnMessageColor;
private System.Windows.Forms.FontDialog dlgFont;
private System.Windows.Forms.RadioButton rdbAutoSizeFitToText;
+ private System.Windows.Forms.Label lblFontColor;
}
}
\ No newline at end of file
diff --git a/InfoBox.Designer/InformationBoxDesigner.cs b/InfoBox.Designer/InformationBoxDesigner.cs
index 188ff71..7811ee7 100644
--- a/InfoBox.Designer/InformationBoxDesigner.cs
+++ b/InfoBox.Designer/InformationBoxDesigner.cs
@@ -35,6 +35,11 @@ public partial class InformationBoxDesigner : Form
///
private Font messageFont = null;
+ ///
+ /// Color for the message text
+ ///
+ private Color messageFontColor = Color.Empty;
+
#endregion Attributes
#region Constructors
@@ -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
@@ -549,12 +557,12 @@ private DesignParameters GetDesign()
/// The font parameters.
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);
}
///
@@ -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;
}
@@ -822,6 +832,33 @@ private void BtnMessageFont_Click(object sender, EventArgs e)
this.messageFont = selected;
}
+ ///
+ /// Handles the Click event of the BtnMessageColor control.
+ ///
+ /// The source of the event.
+ /// The instance containing the event data.
+ 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
diff --git a/InfoBox/Form/InformationBoxForm.cs b/InfoBox/Form/InformationBoxForm.cs
index 21f0f0b..21e5025 100644
--- a/InfoBox/Form/InformationBoxForm.cs
+++ b/InfoBox/Form/InformationBoxForm.cs
@@ -1244,9 +1244,17 @@ private void SetOrder()
///
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;
+ }
}
}
diff --git a/InfoBox/Parameters/FontParameters.cs b/InfoBox/Parameters/FontParameters.cs
index 0fe2c32..49eb4d8 100644
--- a/InfoBox/Parameters/FontParameters.cs
+++ b/InfoBox/Parameters/FontParameters.cs
@@ -22,6 +22,18 @@ public class FontParameters
public FontParameters(Font messageFont)
{
this.MessageFont = messageFont;
+ this.MessageColor = null;
+ }
+
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// The font to use for message text.
+ /// The color to use for message text.
+ public FontParameters(Font messageFont, Color messageColor)
+ {
+ this.MessageFont = messageFont;
+ this.MessageColor = messageColor;
}
#endregion Constructors
@@ -34,8 +46,45 @@ public FontParameters(Font messageFont)
/// The font for the message text.
public Font MessageFont { get; private set; }
+ ///
+ /// Gets the color for the message text.
+ ///
+ /// The color for the message text, or null to use the system default.
+ public Color? MessageColor { get; private set; }
+
#endregion Properties
+ #region Methods
+
+ ///
+ /// Determines whether the current instance has either a font or a color defined.
+ ///
+ /// true if the instance has either a font or a color defined; otherwise, false.
+ public bool IsSet()
+ {
+ return this.HasFont() || this.HasColor();
+ }
+
+ ///
+ /// Determines whether the current instance has a font defined.
+ ///
+ /// true if the instance has a font defined; otherwise, false.
+ public bool HasFont()
+ {
+ return this.MessageFont != null;
+ }
+
+ ///
+ /// Determines whether the current instance has a color defined.
+ ///
+ /// true if the instance has a color defined; otherwise, false.
+ public bool HasColor()
+ {
+ return this.MessageColor.HasValue && this.MessageColor != Color.Empty;
+ }
+
+ #endregion
+
#region Overrides
///
@@ -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;
}
///
@@ -66,7 +116,8 @@ public override bool Equals(object obj)
///
public override int GetHashCode()
{
- return this.MessageFont?.GetHashCode() ?? 0;
+ return (this.MessageFont?.GetHashCode() ?? 0) ^
+ (this.MessageColor?.GetHashCode() ?? 0);
}
#endregion Overrides
diff --git a/InfoBoxCore.Designer.Tests/CodeGeneration/CSharpGeneratorTests.cs b/InfoBoxCore.Designer.Tests/CodeGeneration/CSharpGeneratorTests.cs
index 9b9d501..3439ba7 100644
--- a/InfoBoxCore.Designer.Tests/CodeGeneration/CSharpGeneratorTests.cs
+++ b/InfoBoxCore.Designer.Tests/CodeGeneration/CSharpGeneratorTests.cs
@@ -226,6 +226,123 @@ public void Test0005()
Assert.That(CompileCode(code).Success);
}
+ [Test]
+ public void Test0006_FontParametersWithFontAndColor()
+ {
+ var code = generator.GenerateSingleCall(
+ behavior: InformationBoxBehavior.Modal,
+ text: "Test message with colored font",
+ title: "Test Title",
+ buttons: InformationBoxButtons.OK,
+ button1Text: null,
+ button2Text: null,
+ button3Text: null,
+ icon: InformationBoxIcon.Information,
+ iconFileName: null,
+ defaultButton: InformationBoxDefaultButton.Button1,
+ buttonsLayout: InformationBoxButtonsLayout.GroupMiddle,
+ autoSize: InformationBoxAutoSizeMode.None,
+ position: InformationBoxPosition.CenterOnParent,
+ showHelp: false,
+ helpFile: null,
+ helpTopic: null,
+ navigator: HelpNavigator.TableOfContents,
+ checkState: 0,
+ doNotShowAgainText: null,
+ style: InformationBoxStyle.Standard,
+ useAutoClose: false,
+ autoClose: null,
+ design: null,
+ fontParameters: new FontParameters(new Font("Arial", 12F), Color.Blue),
+ titleStyle: InformationBoxTitleIconStyle.None,
+ titleIconFileName: null,
+ opacity: InformationBoxOpacity.NoFade,
+ order: InformationBoxOrder.Default,
+ sound: InformationBoxSound.Default);
+
+ Assert.That(CompileCode(code).Success, Is.True);
+ Assert.That(code, Does.Contain("Color.FromArgb"));
+ Assert.That(code, Does.Contain("255")); // Blue color component
+ }
+
+ [Test]
+ public void Test0007_FontParametersWithFont()
+ {
+ var code = generator.GenerateSingleCall(
+ behavior: InformationBoxBehavior.Modal,
+ text: "Test message with colored font",
+ title: "Test Title",
+ buttons: InformationBoxButtons.OK,
+ button1Text: null,
+ button2Text: null,
+ button3Text: null,
+ icon: InformationBoxIcon.Information,
+ iconFileName: null,
+ defaultButton: InformationBoxDefaultButton.Button1,
+ buttonsLayout: InformationBoxButtonsLayout.GroupMiddle,
+ autoSize: InformationBoxAutoSizeMode.None,
+ position: InformationBoxPosition.CenterOnParent,
+ showHelp: false,
+ helpFile: null,
+ helpTopic: null,
+ navigator: HelpNavigator.TableOfContents,
+ checkState: 0,
+ doNotShowAgainText: null,
+ style: InformationBoxStyle.Standard,
+ useAutoClose: false,
+ autoClose: null,
+ design: null,
+ fontParameters: new FontParameters(new Font("Arial", 12F)),
+ titleStyle: InformationBoxTitleIconStyle.None,
+ titleIconFileName: null,
+ opacity: InformationBoxOpacity.NoFade,
+ order: InformationBoxOrder.Default,
+ sound: InformationBoxSound.Default);
+
+ Assert.That(CompileCode(code).Success, Is.True);
+ Assert.That(code, Does.Contain("Arial"));
+ Assert.That(code, Does.Contain("12")); // Blue color component
+ }
+
+ [Test]
+ public void Test0008_FontParametersWithColor()
+ {
+ var code = generator.GenerateSingleCall(
+ behavior: InformationBoxBehavior.Modal,
+ text: "Test message with colored font",
+ title: "Test Title",
+ buttons: InformationBoxButtons.OK,
+ button1Text: null,
+ button2Text: null,
+ button3Text: null,
+ icon: InformationBoxIcon.Information,
+ iconFileName: null,
+ defaultButton: InformationBoxDefaultButton.Button1,
+ buttonsLayout: InformationBoxButtonsLayout.GroupMiddle,
+ autoSize: InformationBoxAutoSizeMode.None,
+ position: InformationBoxPosition.CenterOnParent,
+ showHelp: false,
+ helpFile: null,
+ helpTopic: null,
+ navigator: HelpNavigator.TableOfContents,
+ checkState: 0,
+ doNotShowAgainText: null,
+ style: InformationBoxStyle.Standard,
+ useAutoClose: false,
+ autoClose: null,
+ design: null,
+ fontParameters: new FontParameters(null, Color.Blue),
+ titleStyle: InformationBoxTitleIconStyle.None,
+ titleIconFileName: null,
+ opacity: InformationBoxOpacity.NoFade,
+ order: InformationBoxOrder.Default,
+ sound: InformationBoxSound.Default);
+
+ Assert.That(CompileCode(code).Success, Is.True);
+ Assert.That(code, Does.Contain("Color.FromArgb"));
+ Assert.That(code, Does.Contain("255")); // Blue color component
+ }
+
private EmitResult CompileCode(string sourceCode)
{
var result = null as EmitResult;