From bddad91ef572e4086c23b0ba171e4b3df4494aad Mon Sep 17 00:00:00 2001 From: Johann Blais Date: Wed, 21 Jan 2026 18:20:12 +0100 Subject: [PATCH] -Added support for the selection of a specific font for the content (#53) - Added a new autosizing mode to accomodate preformatted text. --- .../CodeGeneration/CSharpGenerator.cs | 8 ++ .../CodeGeneration/ICodeGenerator.cs | 2 + .../CodeGeneration/VbNetGenerator.cs | 9 +- .../InformationBoxDesigner.Designer.cs | 126 +++++++++++++++--- InfoBox.Designer/InformationBoxDesigner.cs | 63 ++++++++- InfoBox.Designer/InformationBoxDesigner.resx | 11 +- .../Context/InformationBoxScopeParameters.cs | 13 ++ InfoBox/Enums/InformationBoxAutoSizeMode.cs | 7 +- InfoBox/Form/InformationBoxForm.Designer.cs | 4 +- InfoBox/Form/InformationBoxForm.cs | 56 +++++++- InfoBox/InfoBox.csproj | 1 + InfoBox/InformationBox.cs | 28 +++- InfoBox/Parameters/FontParameters.cs | 74 ++++++++++ .../CodeGeneration/CSharpGeneratorTests.cs | 5 + 14 files changed, 369 insertions(+), 38 deletions(-) create mode 100644 InfoBox/Parameters/FontParameters.cs diff --git a/InfoBox.Designer/CodeGeneration/CSharpGenerator.cs b/InfoBox.Designer/CodeGeneration/CSharpGenerator.cs index a423fd5..6b1526a 100644 --- a/InfoBox.Designer/CodeGeneration/CSharpGenerator.cs +++ b/InfoBox.Designer/CodeGeneration/CSharpGenerator.cs @@ -38,6 +38,7 @@ public class CSharpGenerator : ICodeGenerator /// if set to true [use auto close]. /// The auto-close parameters. /// The design. + /// The font parameters. /// The title style. /// Filename of the title icon . /// The opacity. @@ -67,6 +68,7 @@ public string GenerateSingleCall(InformationBoxBehavior behavior, bool useAutoClose, AutoCloseParameters autoClose, DesignParameters design, + FontParameters fontParameters, InformationBoxTitleIconStyle titleStyle, string titleIconFileName, InformationBoxOpacity opacity, @@ -222,6 +224,12 @@ 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) + { + codeBuilder.AppendFormat(CultureInfo.InvariantCulture, "fontParameters: new FontParameters(new System.Drawing.Font(\"{0}\", {1}F)), ", + fontParameters.MessageFont.Name, fontParameters.MessageFont.Size); + } + if (titleStyle == InformationBoxTitleIconStyle.Custom) { codeBuilder.AppendFormat(CultureInfo.InvariantCulture, "titleIcon: new InformationBoxTitleIcon(@\"{0}\"), ", titleIconFileName); diff --git a/InfoBox.Designer/CodeGeneration/ICodeGenerator.cs b/InfoBox.Designer/CodeGeneration/ICodeGenerator.cs index 9ceb61c..0aa7297 100644 --- a/InfoBox.Designer/CodeGeneration/ICodeGenerator.cs +++ b/InfoBox.Designer/CodeGeneration/ICodeGenerator.cs @@ -30,6 +30,7 @@ public interface ICodeGenerator /// if set to true [use auto close]. /// The auto-close parameters. /// The design. + /// The font parameters. /// The title style. /// Filename of the title icon . /// The opacity. @@ -59,6 +60,7 @@ string GenerateSingleCall(InformationBoxBehavior behavior, bool useAutoClose, AutoCloseParameters autoClose, DesignParameters design, + FontParameters fontParameters, InformationBoxTitleIconStyle titleStyle, string titleIconFileName, InformationBoxOpacity opacity, diff --git a/InfoBox.Designer/CodeGeneration/VbNetGenerator.cs b/InfoBox.Designer/CodeGeneration/VbNetGenerator.cs index ec66228..d918076 100644 --- a/InfoBox.Designer/CodeGeneration/VbNetGenerator.cs +++ b/InfoBox.Designer/CodeGeneration/VbNetGenerator.cs @@ -34,13 +34,14 @@ public class VbNetGenerator : ICodeGenerator /// if set to true [use auto close]. /// The auto-close parameters. /// The design. + /// The font parameters. /// The title style. /// Filename of the title icon . /// The opacity. /// The order. /// The sound. /// - public string GenerateSingleCall(InformationBoxBehavior behavior, string text, string title, InformationBoxButtons buttons, string button1Text, string button2Text, string button3Text, InformationBoxIcon icon, string iconFileName, InformationBoxDefaultButton defaultButton, InformationBoxButtonsLayout buttonsLayout, InformationBoxAutoSizeMode autoSize, InformationBoxPosition position, bool showHelp, string helpFile, string helpTopic, System.Windows.Forms.HelpNavigator navigator, InformationBoxCheckBox checkState, string doNotShowAgainText, InformationBoxStyle style, bool useAutoClose, AutoCloseParameters autoClose, DesignParameters design, InformationBoxTitleIconStyle titleStyle, string titleIconFileName, InformationBoxOpacity opacity, InformationBoxOrder order, InformationBoxSound sound) + public string GenerateSingleCall(InformationBoxBehavior behavior, string text, string title, InformationBoxButtons buttons, string button1Text, string button2Text, string button3Text, InformationBoxIcon icon, string iconFileName, InformationBoxDefaultButton defaultButton, InformationBoxButtonsLayout buttonsLayout, InformationBoxAutoSizeMode autoSize, InformationBoxPosition position, bool showHelp, string helpFile, string helpTopic, System.Windows.Forms.HelpNavigator navigator, InformationBoxCheckBox checkState, string doNotShowAgainText, InformationBoxStyle style, bool useAutoClose, AutoCloseParameters autoClose, DesignParameters design, FontParameters fontParameters, InformationBoxTitleIconStyle titleStyle, string titleIconFileName, InformationBoxOpacity opacity, InformationBoxOrder order, InformationBoxSound sound) { StringBuilder codeBuilder = new StringBuilder(); if (checkState == 0) @@ -191,6 +192,12 @@ 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) + { + codeBuilder.AppendFormat(CultureInfo.InvariantCulture, "New FontParameters(New Font(\"{0}\", {1}F)), ", + fontParameters.MessageFont.Name, fontParameters.MessageFont.Size); + } + if (titleStyle == InformationBoxTitleIconStyle.Custom) { codeBuilder.AppendFormat(CultureInfo.InvariantCulture, "New InformationBoxTitleIcon(@\"{0}\"), ", titleIconFileName); diff --git a/InfoBox.Designer/InformationBoxDesigner.Designer.cs b/InfoBox.Designer/InformationBoxDesigner.Designer.cs index bed2924..eb0415e 100644 --- a/InfoBox.Designer/InformationBoxDesigner.Designer.cs +++ b/InfoBox.Designer/InformationBoxDesigner.Designer.cs @@ -83,6 +83,7 @@ private void InitializeComponent() ddlLanguage = new System.Windows.Forms.ComboBox(); label4 = new System.Windows.Forms.Label(); groupBox9 = new System.Windows.Forms.GroupBox(); + rdbAutoSizeFitToText = new System.Windows.Forms.RadioButton(); rdbAutoSizeNone = new System.Windows.Forms.RadioButton(); rdbAutoSizeMinimumHeight = new System.Windows.Forms.RadioButton(); rdbAutoSizeMinimumWidth = new System.Windows.Forms.RadioButton(); @@ -141,6 +142,12 @@ private void InitializeComponent() groupBox21 = new System.Windows.Forms.GroupBox(); rdbSoundMute = new System.Windows.Forms.RadioButton(); rdbSoundDefault = new System.Windows.Forms.RadioButton(); + groupBox22 = new System.Windows.Forms.GroupBox(); + chbCustomFonts = new System.Windows.Forms.CheckBox(); + lblMessageFont = new System.Windows.Forms.Label(); + txbMessageFont = new System.Windows.Forms.TextBox(); + btnMessageFont = new System.Windows.Forms.Button(); + dlgFont = new System.Windows.Forms.FontDialog(); groupBox1.SuspendLayout(); groupBox2.SuspendLayout(); groupBox3.SuspendLayout(); @@ -164,6 +171,7 @@ private void InitializeComponent() groupBox19.SuspendLayout(); groupBox20.SuspendLayout(); groupBox21.SuspendLayout(); + groupBox22.SuspendLayout(); SuspendLayout(); // // groupBox1 @@ -214,7 +222,7 @@ private void InitializeComponent() label1.Location = new System.Drawing.Point(21, 24); label1.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); label1.Name = "label1"; - label1.Size = new System.Drawing.Size(29, 15); + label1.Size = new System.Drawing.Size(30, 15); label1.TabIndex = 0; label1.Text = "Title"; // @@ -459,7 +467,7 @@ private void InitializeComponent() // btnShow // btnShow.Anchor = System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left; - btnShow.Location = new System.Drawing.Point(377, 633); + btnShow.Location = new System.Drawing.Point(377, 662); btnShow.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); btnShow.Name = "btnShow"; btnShow.Size = new System.Drawing.Size(214, 31); @@ -535,7 +543,7 @@ private void InitializeComponent() rdbTitleIconSameAsBox.Location = new System.Drawing.Point(86, 18); rdbTitleIconSameAsBox.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); rdbTitleIconSameAsBox.Name = "rdbTitleIconSameAsBox"; - rdbTitleIconSameAsBox.Size = new System.Drawing.Size(87, 19); + rdbTitleIconSameAsBox.Size = new System.Drawing.Size(86, 19); rdbTitleIconSameAsBox.TabIndex = 1; rdbTitleIconSameAsBox.Text = "SameAsBox"; rdbTitleIconSameAsBox.UseVisualStyleBackColor = true; @@ -559,7 +567,7 @@ private void InitializeComponent() txbCode.BackColor = System.Drawing.Color.WhiteSmoke; txbCode.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; txbCode.Font = new System.Drawing.Font("Courier New", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, 0); - txbCode.Location = new System.Drawing.Point(14, 697); + txbCode.Location = new System.Drawing.Point(14, 699); txbCode.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); txbCode.Multiline = true; txbCode.Name = "txbCode"; @@ -572,7 +580,7 @@ private void InitializeComponent() // btnGenerate.Anchor = System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left; btnGenerate.ContextMenuStrip = cmsLanguage; - btnGenerate.Location = new System.Drawing.Point(138, 633); + btnGenerate.Location = new System.Drawing.Point(138, 662); btnGenerate.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); btnGenerate.Name = "btnGenerate"; btnGenerate.Size = new System.Drawing.Size(214, 31); @@ -585,19 +593,19 @@ private void InitializeComponent() // cmsLanguage.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { tsmCSharp, tsmVbNet }); cmsLanguage.Name = "cmsLanguage"; - cmsLanguage.Size = new System.Drawing.Size(113, 48); + cmsLanguage.Size = new System.Drawing.Size(114, 48); // // tsmCSharp // tsmCSharp.Name = "tsmCSharp"; - tsmCSharp.Size = new System.Drawing.Size(112, 22); + tsmCSharp.Size = new System.Drawing.Size(113, 22); tsmCSharp.Text = "C#"; tsmCSharp.Click += tsmCSharp_Click; // // tsmVbNet // tsmVbNet.Name = "tsmVbNet"; - tsmVbNet.Size = new System.Drawing.Size(112, 22); + tsmVbNet.Size = new System.Drawing.Size(113, 22); tsmVbNet.Text = "VB.NET"; tsmVbNet.Click += tsmVbNet_Click; // @@ -745,6 +753,7 @@ private void InitializeComponent() // // groupBox9 // + groupBox9.Controls.Add(rdbAutoSizeFitToText); groupBox9.Controls.Add(rdbAutoSizeNone); groupBox9.Controls.Add(rdbAutoSizeMinimumHeight); groupBox9.Controls.Add(rdbAutoSizeMinimumWidth); @@ -757,6 +766,17 @@ private void InitializeComponent() groupBox9.TabStop = false; groupBox9.Text = "AutoSize"; // + // rdbAutoSizeFitToText + // + rdbAutoSizeFitToText.AutoSize = true; + rdbAutoSizeFitToText.Location = new System.Drawing.Point(172, 45); + rdbAutoSizeFitToText.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); + rdbAutoSizeFitToText.Name = "rdbAutoSizeFitToText"; + rdbAutoSizeFitToText.Size = new System.Drawing.Size(72, 19); + rdbAutoSizeFitToText.TabIndex = 3; + rdbAutoSizeFitToText.Text = "FitToText"; + rdbAutoSizeFitToText.UseVisualStyleBackColor = true; + // // rdbAutoSizeNone // rdbAutoSizeNone.AutoSize = true; @@ -789,7 +809,6 @@ private void InitializeComponent() rdbAutoSizeMinimumWidth.Name = "rdbAutoSizeMinimumWidth"; rdbAutoSizeMinimumWidth.Size = new System.Drawing.Size(110, 19); rdbAutoSizeMinimumWidth.TabIndex = 0; - rdbAutoSizeMinimumWidth.TabStop = true; rdbAutoSizeMinimumWidth.Text = "MinimumWidth"; rdbAutoSizeMinimumWidth.UseVisualStyleBackColor = true; // @@ -931,7 +950,7 @@ private void InitializeComponent() rdbHelpTopic.Location = new System.Drawing.Point(174, 45); rdbHelpTopic.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); rdbHelpTopic.Name = "rdbHelpTopic"; - rdbHelpTopic.Size = new System.Drawing.Size(53, 19); + rdbHelpTopic.Size = new System.Drawing.Size(54, 19); rdbHelpTopic.TabIndex = 7; rdbHelpTopic.TabStop = true; rdbHelpTopic.Text = "Topic"; @@ -943,7 +962,7 @@ private void InitializeComponent() rdbHelpTableOfContents.Location = new System.Drawing.Point(174, 21); rdbHelpTableOfContents.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); rdbHelpTableOfContents.Name = "rdbHelpTableOfContents"; - rdbHelpTableOfContents.Size = new System.Drawing.Size(113, 19); + rdbHelpTableOfContents.Size = new System.Drawing.Size(114, 19); rdbHelpTableOfContents.TabIndex = 3; rdbHelpTableOfContents.TabStop = true; rdbHelpTableOfContents.Text = "TableOfContents"; @@ -955,7 +974,7 @@ private void InitializeComponent() rdbHelpIndex.Location = new System.Drawing.Point(22, 44); rdbHelpIndex.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); rdbHelpIndex.Name = "rdbHelpIndex"; - rdbHelpIndex.Size = new System.Drawing.Size(54, 19); + rdbHelpIndex.Size = new System.Drawing.Size(53, 19); rdbHelpIndex.TabIndex = 2; rdbHelpIndex.TabStop = true; rdbHelpIndex.Text = "Index"; @@ -993,7 +1012,7 @@ private void InitializeComponent() label9.Location = new System.Drawing.Point(14, 73); label9.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); label9.Name = "label9"; - label9.Size = new System.Drawing.Size(72, 15); + label9.Size = new System.Drawing.Size(71, 15); label9.TabIndex = 6; label9.Text = "Custom text"; // @@ -1010,14 +1029,13 @@ private void InitializeComponent() clbCheckBox.BackColor = System.Drawing.SystemColors.Control; clbCheckBox.BorderStyle = System.Windows.Forms.BorderStyle.None; clbCheckBox.CheckOnClick = true; - clbCheckBox.ColumnWidth = 78; - clbCheckBox.FormattingEnabled = true; + clbCheckBox.ColumnWidth = 100; clbCheckBox.Items.AddRange(new object[] { "Show", "Checked", "RightAligned" }); - clbCheckBox.Location = new System.Drawing.Point(7, 35); + clbCheckBox.Location = new System.Drawing.Point(7, 17); clbCheckBox.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); clbCheckBox.MultiColumn = true; clbCheckBox.Name = "clbCheckBox"; - clbCheckBox.Size = new System.Drawing.Size(296, 0); + clbCheckBox.Size = new System.Drawing.Size(296, 36); clbCheckBox.TabIndex = 0; // // groupBox15 @@ -1305,7 +1323,7 @@ private void InitializeComponent() // btnShowModeless // btnShowModeless.Anchor = System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left; - btnShowModeless.Location = new System.Drawing.Point(616, 633); + btnShowModeless.Location = new System.Drawing.Point(616, 662); btnShowModeless.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); btnShowModeless.Name = "btnShowModeless"; btnShowModeless.Size = new System.Drawing.Size(214, 31); @@ -1339,7 +1357,7 @@ private void InitializeComponent() // groupBox20.Controls.Add(rdbOrderTopMost); groupBox20.Controls.Add(rdbOrderDefault); - groupBox20.Location = new System.Drawing.Point(14, 547); + groupBox20.Location = new System.Drawing.Point(329, 603); groupBox20.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); groupBox20.Name = "groupBox20"; groupBox20.Padding = new System.Windows.Forms.Padding(4, 3, 4, 3); @@ -1354,7 +1372,7 @@ private void InitializeComponent() rdbOrderTopMost.Location = new System.Drawing.Point(172, 21); rdbOrderTopMost.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); rdbOrderTopMost.Name = "rdbOrderTopMost"; - rdbOrderTopMost.Size = new System.Drawing.Size(71, 19); + rdbOrderTopMost.Size = new System.Drawing.Size(72, 19); rdbOrderTopMost.TabIndex = 1; rdbOrderTopMost.Text = "TopMost"; rdbOrderTopMost.UseVisualStyleBackColor = true; @@ -1409,11 +1427,68 @@ private void InitializeComponent() rdbSoundDefault.Text = "Default"; rdbSoundDefault.UseVisualStyleBackColor = true; // + // groupBox22 + // + groupBox22.Controls.Add(chbCustomFonts); + groupBox22.Controls.Add(lblMessageFont); + groupBox22.Controls.Add(txbMessageFont); + groupBox22.Controls.Add(btnMessageFont); + 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.TabIndex = 25; + groupBox22.TabStop = false; + groupBox22.Text = "Font"; + // + // chbCustomFonts + // + chbCustomFonts.AutoSize = true; + chbCustomFonts.Location = new System.Drawing.Point(21, 22); + chbCustomFonts.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); + chbCustomFonts.Name = "chbCustomFonts"; + chbCustomFonts.Size = new System.Drawing.Size(204, 19); + chbCustomFonts.TabIndex = 0; + chbCustomFonts.Text = "Use a custom font for the content"; + chbCustomFonts.UseVisualStyleBackColor = true; + // + // lblMessageFont + // + lblMessageFont.AutoSize = true; + lblMessageFont.Location = new System.Drawing.Point(8, 50); + lblMessageFont.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); + lblMessageFont.Name = "lblMessageFont"; + lblMessageFont.Size = new System.Drawing.Size(31, 15); + lblMessageFont.TabIndex = 1; + lblMessageFont.Text = "Font"; + // + // txbMessageFont + // + txbMessageFont.Location = new System.Drawing.Point(59, 47); + txbMessageFont.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); + txbMessageFont.Name = "txbMessageFont"; + txbMessageFont.ReadOnly = true; + txbMessageFont.Size = new System.Drawing.Size(182, 23); + txbMessageFont.TabIndex = 2; + // + // btnMessageFont + // + btnMessageFont.Location = new System.Drawing.Point(250, 45); + btnMessageFont.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); + btnMessageFont.Name = "btnMessageFont"; + btnMessageFont.Size = new System.Drawing.Size(29, 25); + btnMessageFont.TabIndex = 3; + btnMessageFont.Text = "..."; + btnMessageFont.UseVisualStyleBackColor = true; + btnMessageFont.Click += BtnMessageFont_Click; + // // InformationBoxDesigner // AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - ClientSize = new System.Drawing.Size(966, 788); + ClientSize = new System.Drawing.Size(966, 790); + Controls.Add(groupBox22); Controls.Add(groupBox21); Controls.Add(groupBox20); Controls.Add(groupBox19); @@ -1488,6 +1563,8 @@ private void InitializeComponent() groupBox20.PerformLayout(); groupBox21.ResumeLayout(false); groupBox21.PerformLayout(); + groupBox22.ResumeLayout(false); + groupBox22.PerformLayout(); ResumeLayout(false); PerformLayout(); } @@ -1605,5 +1682,12 @@ private void InitializeComponent() private System.Windows.Forms.TextBox txbUser3; private System.Windows.Forms.Label label9; private System.Windows.Forms.TextBox txtDoNotShowText; + private System.Windows.Forms.GroupBox groupBox22; + private System.Windows.Forms.CheckBox chbCustomFonts; + private System.Windows.Forms.Label lblMessageFont; + private System.Windows.Forms.TextBox txbMessageFont; + private System.Windows.Forms.Button btnMessageFont; + private System.Windows.Forms.FontDialog dlgFont; + private System.Windows.Forms.RadioButton rdbAutoSizeFitToText; } } \ No newline at end of file diff --git a/InfoBox.Designer/InformationBoxDesigner.cs b/InfoBox.Designer/InformationBoxDesigner.cs index 5d628b5..188ff71 100644 --- a/InfoBox.Designer/InformationBoxDesigner.cs +++ b/InfoBox.Designer/InformationBoxDesigner.cs @@ -30,6 +30,11 @@ public partial class InformationBoxDesigner : Form /// private Color formColor = Color.Empty; + /// + /// Font for the message text + /// + private Font messageFont = null; + #endregion Attributes #region Constructors @@ -82,6 +87,7 @@ private void ShowBox(InformationBoxBehavior behavior) InformationBoxStyle style = this.GetStyle(); AutoCloseParameters autoClose = this.GetAutoClose(); DesignParameters design = this.GetDesign(); + FontParameters fontParameters = this.GetFontParameters(); InformationBoxTitleIconStyle titleStyle = this.GetTitleStyle(); InformationBoxOpacity opacity = this.GetOpacity(); InformationBoxOrder order = this.GetOrder(); @@ -95,11 +101,11 @@ private void ShowBox(InformationBoxBehavior behavior) if (String.IsNullOrEmpty(iconFileName)) { - InformationBox.Show(this.txbText.Text, out state, this.txbTitle.Text, buttons, new string[] { this.txbUser1.Text, this.txbUser2.Text, this.txbUser3.Text }, icon, defaultButton, buttonsLayout, autoSize, position, this.chbHelpButton.Checked, this.txbHelpFile.Text, navigator, this.txbHelpTopic.Text, checkState, doNotShowAgainText, style, autoClose, design, titleStyle, titleIcon, behavior, new AsyncResultCallback(BoxClosed), opacity, order, sound); + InformationBox.Show(this.txbText.Text, out state, this.txbTitle.Text, buttons, new string[] { this.txbUser1.Text, this.txbUser2.Text, this.txbUser3.Text }, icon, defaultButton, buttonsLayout, autoSize, position, this.chbHelpButton.Checked, this.txbHelpFile.Text, navigator, this.txbHelpTopic.Text, checkState, doNotShowAgainText, style, autoClose, design, fontParameters, titleStyle, titleIcon, behavior, new AsyncResultCallback(BoxClosed), opacity, order, sound); } else { - InformationBox.Show(this.txbText.Text, out state, this.txbTitle.Text, buttons, new string[] { this.txbUser1.Text, this.txbUser2.Text, this.txbUser3.Text }, new Icon(iconFileName), defaultButton, buttonsLayout, autoSize, position, this.chbHelpButton.Checked, this.txbHelpFile.Text, navigator, this.txbHelpTopic.Text, checkState, doNotShowAgainText, style, autoClose, design, titleStyle, titleIcon, behavior, new AsyncResultCallback(BoxClosed), opacity, order, sound); + InformationBox.Show(this.txbText.Text, out state, this.txbTitle.Text, buttons, new string[] { this.txbUser1.Text, this.txbUser2.Text, this.txbUser3.Text }, new Icon(iconFileName), defaultButton, buttonsLayout, autoSize, position, this.chbHelpButton.Checked, this.txbHelpFile.Text, navigator, this.txbHelpTopic.Text, checkState, doNotShowAgainText, style, autoClose, design, fontParameters, titleStyle, titleIcon, behavior, new AsyncResultCallback(BoxClosed), opacity, order, sound); } if (checkState != 0) @@ -186,6 +192,10 @@ private void LoadBindings() this.lblTitleIcon.DataBindings.Add("Enabled", this.rdbTitleIconCustom, "Checked"); this.txbTitleIconFile.DataBindings.Add("Enabled", this.rdbTitleIconCustom, "Checked"); this.btnTitleIconFile.DataBindings.Add("Enabled", this.rdbTitleIconCustom, "Checked"); + + this.lblMessageFont.DataBindings.Add("Enabled", this.chbCustomFonts, "Checked"); + this.txbMessageFont.DataBindings.Add("Enabled", this.chbCustomFonts, "Checked"); + this.btnMessageFont.DataBindings.Add("Enabled", this.chbCustomFonts, "Checked"); } #endregion Loading @@ -353,6 +363,11 @@ private InformationBoxAutoSizeMode GetAutoSize() return InformationBoxAutoSizeMode.MinimumWidth; } + if (this.rdbAutoSizeFitToText.Checked) + { + return InformationBoxAutoSizeMode.FitToText; + } + return InformationBoxAutoSizeMode.None; } @@ -528,6 +543,20 @@ private DesignParameters GetDesign() return new DesignParameters(this.formColor, this.barsColor); } + /// + /// Gets the font parameters. + /// + /// The font parameters. + private FontParameters GetFontParameters() + { + if (!this.chbCustomFonts.Checked || this.messageFont == null) + { + return null; + } + + return new FontParameters(this.messageFont); + } + /// /// Gets the title style. /// @@ -575,6 +604,7 @@ private void GenerateCode(InformationBoxBehavior behavior, Language language) var style = this.GetStyle(); var autoClose = this.GetAutoClose(); var design = this.GetDesign(); + var fontParameters = this.GetFontParameters(); var titleStyle = this.GetTitleStyle(); var opacity = this.GetOpacity(); var order = this.GetOrder(); @@ -587,7 +617,7 @@ private void GenerateCode(InformationBoxBehavior behavior, Language language) behavior, this.txbText.Text, this.txbTitle.Text, buttons, this.txbUser1.Text, this.txbUser2.Text, this.txbUser3.Text, icon, iconFileName, defaultButton, buttonsLayout, autoSize, position, this.chbHelpButton.Checked, this.txbHelpFile.Text, this.txbHelpTopic.Text, navigator, checkState, doNotShowAgainText, style, this.chbActivateAutoClose.Checked, - autoClose, design, titleStyle, this.txbTitleIconFile.Text, opacity, order, sound); + autoClose, design, fontParameters, titleStyle, this.txbTitleIconFile.Text, opacity, order, sound); this.txbCode.Text = generatedCode; } @@ -767,6 +797,33 @@ private void BtnColorsForm_Click(object sender, EventArgs e) #endregion Colors + #region Fonts + + /// + /// Handles the Click event of the btnMessageFont control. + /// + /// The source of the event. + /// The instance containing the event data. + private void BtnMessageFont_Click(object sender, EventArgs e) + { + if (this.messageFont != null) + { + this.dlgFont.Font = this.messageFont; + } + + if (this.dlgFont.ShowDialog() != DialogResult.OK) + { + return; + } + + Font selected = this.dlgFont.Font; + + this.txbMessageFont.Text = string.Format("{0}, {1}pt", selected.Name, selected.Size); + this.messageFont = selected; + } + + #endregion Fonts + #endregion Event handlers } } \ No newline at end of file diff --git a/InfoBox.Designer/InformationBoxDesigner.resx b/InfoBox.Designer/InformationBoxDesigner.resx index 49703e6..b079295 100644 --- a/InfoBox.Designer/InformationBoxDesigner.resx +++ b/InfoBox.Designer/InformationBoxDesigner.resx @@ -118,16 +118,19 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - 311, 17 + 422, 17 - 17, 17 + 112, 17 - 106, 17 + 207, 17 - 213, 17 + 322, 17 + + + 17, 17 50 diff --git a/InfoBox/Context/InformationBoxScopeParameters.cs b/InfoBox/Context/InformationBoxScopeParameters.cs index 6f5d2c1..b501fef 100644 --- a/InfoBox/Context/InformationBoxScopeParameters.cs +++ b/InfoBox/Context/InformationBoxScopeParameters.cs @@ -121,6 +121,12 @@ public struct InformationBoxScopeParameters /// The design. public DesignParameters Design { get; set; } + /// + /// Gets or sets the font. + /// + /// The font. + public FontParameters Font { get; set; } + /// /// Gets or sets the order. /// @@ -199,6 +205,11 @@ public InformationBoxScopeParameters Merge(InformationBoxScopeParameters paramet this.Design = parameters.Design; } + if (parameters.Font != null && null == this.Font) + { + this.Font = parameters.Font; + } + if (parameters.TitleIconStyle.HasValue && !this.TitleIconStyle.HasValue) { this.TitleIconStyle = parameters.TitleIconStyle.Value; @@ -275,6 +286,7 @@ public override bool Equals(object obj) this.CustomIcon == compared.CustomIcon && this.DefaultButton == compared.DefaultButton && this.Design == compared.Design && + this.Font == compared.Font && this.Help == compared.Help && this.HelpNavigator == compared.HelpNavigator && this.Icon == compared.Icon && @@ -305,6 +317,7 @@ public override int GetHashCode() hashCode ^= this.CustomIcon == null ? 0 : this.CustomIcon.GetHashCode(); hashCode ^= this.DefaultButton == null ? 0 : this.DefaultButton.GetHashCode(); hashCode ^= this.Design == null ? 0 : this.Design.GetHashCode(); + hashCode ^= this.Font == null ? 0 : this.Font.GetHashCode(); hashCode ^= this.Help == null ? 0 : this.Help.GetHashCode(); hashCode ^= this.HelpNavigator == null ? 0 : this.HelpNavigator.GetHashCode(); hashCode ^= this.Icon == null ? 0 : this.Icon.GetHashCode(); diff --git a/InfoBox/Enums/InformationBoxAutoSizeMode.cs b/InfoBox/Enums/InformationBoxAutoSizeMode.cs index 4e9f475..76f2153 100644 --- a/InfoBox/Enums/InformationBoxAutoSizeMode.cs +++ b/InfoBox/Enums/InformationBoxAutoSizeMode.cs @@ -22,8 +22,13 @@ public enum InformationBoxAutoSizeMode MinimumHeight, /// - /// The will be set according to existing line breaks. + /// The will be set with consideration for existing line breaks, but will wrapping lines that are too wide. /// None, + + /// + /// The will try to adjust the size so that the text is displayed as provided. It enbale pre-formatted text to remain untouched. In case the text is wider than the screen, horizontal scrollbars will appear. + /// + FitToText } } diff --git a/InfoBox/Form/InformationBoxForm.Designer.cs b/InfoBox/Form/InformationBoxForm.Designer.cs index 726e982..d8e3968 100644 --- a/InfoBox/Form/InformationBoxForm.Designer.cs +++ b/InfoBox/Form/InformationBoxForm.Designer.cs @@ -188,8 +188,8 @@ private void InitializeComponent() // // InformationBoxForm // - this.AutoScaleDimensions = new System.Drawing.SizeF(96F, 96F); - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Dpi; + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(257, 153); this.Controls.Add(this.pnlForm); this.DoubleBuffered = true; diff --git a/InfoBox/Form/InformationBoxForm.cs b/InfoBox/Form/InformationBoxForm.cs index 0435347..94f9392 100644 --- a/InfoBox/Form/InformationBoxForm.cs +++ b/InfoBox/Form/InformationBoxForm.cs @@ -33,7 +33,7 @@ internal partial class InformationBoxForm : Form /// /// Padding for the borders /// - private const int BorderPadding = 10; + private const int BorderPadding = 20; #endregion Consts @@ -144,6 +144,11 @@ internal partial class InformationBoxForm : Form /// private DesignParameters design; + /// + /// Contains the font parameters + /// + private FontParameters fontParameters; + /// /// Contains the style of the title /// @@ -237,6 +242,7 @@ internal partial class InformationBoxForm : Form /// The style. /// The auto close configuration. /// The design. + /// The font parameters. /// The title style. /// The title icon. /// The legacy buttons. @@ -268,6 +274,7 @@ internal InformationBoxForm(string text, InformationBoxStyle style = InformationBoxStyle.Standard, AutoCloseParameters autoClose = null, DesignParameters design = null, + FontParameters fontParameters = null, InformationBoxTitleIconStyle titleStyle = InformationBoxTitleIconStyle.None, InformationBoxTitleIcon titleIcon = null, MessageBoxButtons? legacyButtons = null, @@ -282,6 +289,7 @@ internal InformationBoxForm(string text, { this.InitializeComponent(); this.measureGraphics = CreateGraphics(); + this.measureGraphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias; // Apply default font for message boxes this.Font = SystemFonts.MessageBoxFont; @@ -334,6 +342,7 @@ internal InformationBoxForm(string text, this.style = style; this.autoClose = autoClose; this.design = design; + this.fontParameters = fontParameters; this.titleStyle = titleStyle; if (titleIcon != null) { @@ -508,6 +517,16 @@ internal InformationBoxForm(string text, params object[] parameters) // Design parameters this.design = (DesignParameters)parameter; } + else if (parameter is FontParameters) + { + // Font parameters + this.fontParameters = (FontParameters)parameter; + } + else if (parameter is Font) + { + // Direct font parameter - use for both message and title + this.fontParameters = new FontParameters((Font)parameter); + } else if (parameter is InformationBoxTitleIconStyle) { // Title style @@ -578,6 +597,7 @@ internal InformationBoxForm(string text, params object[] parameters) { this.SetCheckBox(); this.SetButtons(); + this.SetFont(); this.SetText(); this.SetIcon(); this.SetLayout(); @@ -733,6 +753,11 @@ private void LoadCurrentScope() this.design = parameters.Design; } + if (parameters.Font != null) + { + this.fontParameters = parameters.Font; + } + if (parameters.TitleIconStyle.HasValue) { this.titleStyle = parameters.TitleIconStyle.Value; @@ -1202,6 +1227,21 @@ private void SetOrder() #endregion Z-Order + #region Font + + /// + /// Sets the font. + /// + private void SetFont() + { + if (this.fontParameters != null && this.fontParameters.MessageFont != null) + { + this.messageText.Font = this.fontParameters.MessageFont; + } + } + + #endregion Font + #region Text /// @@ -1218,7 +1258,15 @@ private void SetText() if (this.autoSizeMode == InformationBoxAutoSizeMode.None) { this.messageText.WordWrap = true; - this.messageText.Size = this.measureGraphics.MeasureString(this.messageText.Text, this.messageText.Font, screenWidth / 2).ToSize(); + this.messageText.Size = (this.measureGraphics.MeasureString(this.messageText.Text, this.messageText.Font, screenWidth / 2) + new SizeF(1, 0)).ToSize(); + } + else if (this.autoSizeMode == InformationBoxAutoSizeMode.FitToText) + { + var stringFormat = StringFormat.GenericTypographic; + stringFormat.FormatFlags = StringFormatFlags.NoWrap | StringFormatFlags.MeasureTrailingSpaces; + + this.messageText.WordWrap = false; + this.messageText.Size = (this.measureGraphics.MeasureString(this.messageText.Text, this.messageText.Font, screenWidth, stringFormat) + new SizeF(1, 0)).ToSize(); } else { @@ -1235,7 +1283,7 @@ private void SetText() foreach (Match sentence in sentences) { - int sentenceLength = (int)this.measureGraphics.MeasureString(sentence.Value, messageText.Font).Width; + int sentenceLength = (int)this.measureGraphics.MeasureString(sentence.Value, this.messageText.Font).Width; if (currentWidth != 0 && (sentenceLength + currentWidth) > (screenWidth - 50)) { formattedText.Append(Environment.NewLine); @@ -1260,7 +1308,7 @@ private void SetText() this.messageText.Text = this.internalText.ToString(); - this.messageText.Size = this.measureGraphics.MeasureString(this.messageText.Text, this.messageText.Font).ToSize(); + this.messageText.Size = (this.measureGraphics.MeasureString(this.messageText.Text, this.messageText.Font) + new SizeF(1, 0)).ToSize(); } this.messageText.Width += BorderPadding; diff --git a/InfoBox/InfoBox.csproj b/InfoBox/InfoBox.csproj index e2df245..d019647 100644 --- a/InfoBox/InfoBox.csproj +++ b/InfoBox/InfoBox.csproj @@ -162,6 +162,7 @@ + diff --git a/InfoBox/InformationBox.cs b/InfoBox/InformationBox.cs index 602d0a9..25423f5 100644 --- a/InfoBox/InformationBox.cs +++ b/InfoBox/InformationBox.cs @@ -91,6 +91,14 @@ public static class InformationBox /// the parameters for the design (colors). /// /// + /// + /// the parameters for customizing the message text font. + /// + /// + /// + /// the font to use for message text. + /// + /// /// /// which icon will be displayed in the title bar. /// @@ -151,6 +159,8 @@ public static InformationBoxResult Show(string text, params object[] parameters) /// The style. /// The auto close configuration. /// The design. + /// The font parameters. + /// The specific font to use for the content. /// The title style. /// The title icon. /// The legacy buttons. @@ -183,6 +193,8 @@ public static InformationBoxResult Show(string text, InformationBoxStyle style = InformationBoxStyle.Standard, AutoCloseParameters autoClose = null, DesignParameters design = null, + FontParameters fontParameters = null, + Font font = null, InformationBoxTitleIconStyle titleStyle = InformationBoxTitleIconStyle.None, InformationBoxTitleIcon titleIcon = null, MessageBoxButtons? legacyButtons = null, @@ -197,7 +209,7 @@ public static InformationBoxResult Show(string text, { return new InformationBoxForm(text, title, helpFile, helpTopic, initialization, buttons, icon, customIcon, defaultButton, customButtons, buttonsLayout, autoSizeMode, position, showHelpButton, helpNavigator, showDoNotShowAgainCheckBox, doNotShowAgainText, - style, autoClose, design, titleStyle, titleIcon, legacyButtons, legacyIcon, legacyDefaultButton, behavior, callback, opacity, parent, order, sound).Show(); + style, autoClose, design, fontParameters, font, titleStyle, titleIcon, legacyButtons, legacyIcon, legacyDefaultButton, behavior, callback, opacity, parent, order, sound).Show(); } /// @@ -275,6 +287,14 @@ public static InformationBoxResult Show(string text, /// the parameters for the design (colors). /// /// + /// + /// the parameters for customizing the message text font. + /// + /// + /// + /// the font to use for message text. + /// + /// /// /// which icon will be displayed in the title bar. /// @@ -347,6 +367,8 @@ public static InformationBoxResult Show(string text, out CheckState checkBoxStat /// The style. /// The auto close configuration. /// The design. + /// The font parameters. + /// The specific font to use for the content. /// The title style. /// The title icon. /// The legacy buttons. @@ -382,6 +404,8 @@ public static InformationBoxResult Show(string text, InformationBoxStyle style = InformationBoxStyle.Standard, AutoCloseParameters autoClose = null, DesignParameters design = null, + FontParameters fontParameters = null, + Font font = null, InformationBoxTitleIconStyle titleStyle = InformationBoxTitleIconStyle.None, InformationBoxTitleIcon titleIcon = null, MessageBoxButtons? legacyButtons = null, @@ -396,7 +420,7 @@ public static InformationBoxResult Show(string text, { return new InformationBoxForm(text, title, helpFile, helpTopic, initialization, buttons, icon, customIcon, defaultButton, customButtons, buttonsLayout, autoSizeMode, position, showHelpButton, helpNavigator, showDoNotShowAgainCheckBox, doNotShowAgainText, - style, autoClose, design, titleStyle, titleIcon, legacyButtons, legacyIcon, legacyDefaultButton, behavior, callback, opacity, parent, order, sound).Show(out checkBoxState); + style, autoClose, design, fontParameters, font, titleStyle, titleIcon, legacyButtons, legacyIcon, legacyDefaultButton, behavior, callback, opacity, parent, order, sound).Show(out checkBoxState); } #endregion Show diff --git a/InfoBox/Parameters/FontParameters.cs b/InfoBox/Parameters/FontParameters.cs new file mode 100644 index 0000000..0fe2c32 --- /dev/null +++ b/InfoBox/Parameters/FontParameters.cs @@ -0,0 +1,74 @@ +// +// Copyright (c) 2026 All Right Reserved +// +// Johann Blais +// Contains the font parameters for customizing text display + +namespace InfoBox +{ + using System.Drawing; + + /// + /// Contains the font parameters for customizing message text display. + /// + public class FontParameters + { + #region Constructors + + /// + /// Initializes a new instance of the class. + /// + /// The font to use for message text. + public FontParameters(Font messageFont) + { + this.MessageFont = messageFont; + } + + #endregion Constructors + + #region Properties + + /// + /// Gets the font for the message text. + /// + /// The font for the message text. + public Font MessageFont { get; private set; } + + #endregion Properties + + #region Overrides + + /// + /// Determines whether the specified is equal to the current . + /// + /// The to compare with the current . + /// + /// true if the specified is equal to the current ; otherwise, false. + /// + /// The parameter is null. + public override bool Equals(object obj) + { + if (obj == null || GetType() != obj.GetType()) + { + return false; + } + + FontParameters compared = (FontParameters)obj; + + return object.Equals(this.MessageFont, compared.MessageFont); + } + + /// + /// Serves as a hash function for a particular type. + /// + /// + /// A hash code for the current . + /// + public override int GetHashCode() + { + return this.MessageFont?.GetHashCode() ?? 0; + } + + #endregion Overrides + } +} diff --git a/InfoBoxCore.Designer.Tests/CodeGeneration/CSharpGeneratorTests.cs b/InfoBoxCore.Designer.Tests/CodeGeneration/CSharpGeneratorTests.cs index 6143e92..9b9d501 100644 --- a/InfoBoxCore.Designer.Tests/CodeGeneration/CSharpGeneratorTests.cs +++ b/InfoBoxCore.Designer.Tests/CodeGeneration/CSharpGeneratorTests.cs @@ -72,6 +72,7 @@ public void Test0001() useAutoClose: false, autoClose: null, design: null, + fontParameters: null, titleStyle: InformationBoxTitleIconStyle.SameAsBox, titleIconFileName: null, opacity: InformationBoxOpacity.NoFade, @@ -107,6 +108,7 @@ public void Test0002() useAutoClose: false, autoClose: null, design: null, + fontParameters: null, titleStyle: InformationBoxTitleIconStyle.SameAsBox, titleIconFileName: null, opacity: InformationBoxOpacity.NoFade, @@ -142,6 +144,7 @@ public void Test0003() useAutoClose: false, autoClose: null, design: null, + fontParameters: null, titleStyle: InformationBoxTitleIconStyle.SameAsBox, titleIconFileName: null, opacity: InformationBoxOpacity.NoFade, @@ -177,6 +180,7 @@ public void Test0004() useAutoClose: false, autoClose: null, design: new DesignParameters(Color.Red, Color.Green), + fontParameters: null, titleStyle: InformationBoxTitleIconStyle.SameAsBox, titleIconFileName: null, opacity: InformationBoxOpacity.NoFade, @@ -212,6 +216,7 @@ public void Test0005() useAutoClose: false, autoClose: null, design: new DesignParameters(Color.Red, Color.Green), + fontParameters: null, titleStyle: InformationBoxTitleIconStyle.SameAsBox, titleIconFileName: null, opacity: InformationBoxOpacity.NoFade,