diff --git a/InfoBox/Form/InformationBoxForm.cs b/InfoBox/Form/InformationBoxForm.cs
index 2328125..5c0593e 100644
--- a/InfoBox/Form/InformationBoxForm.cs
+++ b/InfoBox/Form/InformationBoxForm.cs
@@ -74,11 +74,6 @@ internal partial class InformationBoxForm : Form
///
private readonly string doNotShowAgainText;
- ///
- /// Contains the graphics used to measure the strings
- ///
- private readonly Graphics measureGraphics;
-
///
/// Contains a reference to the active form
///
@@ -288,8 +283,6 @@ internal InformationBoxForm(string text,
InformationBoxSound sound = InformationBoxSound.Default)
{
this.InitializeComponent();
- this.measureGraphics = CreateGraphics();
- this.measureGraphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias;
// Apply default font for message boxes
this.Font = SystemFonts.MessageBoxFont;
@@ -1007,7 +1000,7 @@ private void SetLayout()
#region Width
// Caption width including button
- int captionWidth = Convert.ToInt32(this.measureGraphics.MeasureString(Text, SystemFonts.CaptionFont).Width) + 30;
+ int captionWidth = TextRenderer.MeasureText(Text, SystemFonts.CaptionFont, Size.Empty, TextFormatFlags.NoPadding | TextFormatFlags.NoPrefix).Width + 30;
if (this.titleStyle != InformationBoxTitleIconStyle.None)
{
captionWidth += BorderPadding * 2;
@@ -1015,7 +1008,7 @@ private void SetLayout()
// "Do not show this dialog again" width
int checkBoxWidth = ((this.checkBox & InformationBoxCheckBox.Show) == InformationBoxCheckBox.Show)
- ? (int)this.measureGraphics.MeasureString(this.chbDoNotShow.Text, this.chbDoNotShow.Font).Width + BorderPadding * 4
+ ? TextRenderer.MeasureText(this.chbDoNotShow.Text, this.chbDoNotShow.Font, Size.Empty, TextFormatFlags.NoPadding).Width + BorderPadding * 4
: 0;
// Width of the text and icon.
@@ -1273,7 +1266,7 @@ 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) + new SizeF(1, 0)).ToSize();
+ this.messageText.Size = TextRenderer.MeasureText(this.messageText.Text, this.messageText.Font, new Size(screenWidth / 2, 0), TextFormatFlags.TextBoxControl | TextFormatFlags.WordBreak);
}
else
{
@@ -1290,7 +1283,7 @@ private void SetText()
foreach (Match sentence in sentences)
{
- int sentenceLength = (int)this.measureGraphics.MeasureString(sentence.Value, this.messageText.Font).Width;
+ int sentenceLength = TextRenderer.MeasureText(sentence.Value, this.messageText.Font, Size.Empty, TextFormatFlags.TextBoxControl | TextFormatFlags.NoPadding).Width;
if (currentWidth != 0 && (sentenceLength + currentWidth) > (screenWidth - 50))
{
formattedText.Append(Environment.NewLine);
@@ -1315,7 +1308,7 @@ private void SetText()
this.messageText.Text = this.internalText.ToString();
- this.messageText.Size = (this.measureGraphics.MeasureString(this.messageText.Text, this.messageText.Font) + new SizeF(1, 0)).ToSize();
+ this.messageText.Size = TextRenderer.MeasureText(this.messageText.Text, this.messageText.Font, Size.Empty, TextFormatFlags.TextBoxControl);
}
}
@@ -1426,7 +1419,7 @@ private void SetButtonsSize()
// Measures the width of each button
foreach (Control ctrl in this.pnlButtons.Controls)
{
- maxSize = Math.Max(Convert.ToInt32(this.measureGraphics.MeasureString(ctrl.Text, ctrl.Font).Width + 40), maxSize);
+ maxSize = Math.Max(TextRenderer.MeasureText(ctrl.Text, ctrl.Font, Size.Empty, TextFormatFlags.NoPadding | TextFormatFlags.NoPrefix).Width + 40, maxSize);
}
foreach (Control ctrl in this.pnlButtons.Controls)
diff --git a/InfoBox/InfoBox.nuspec b/InfoBox/InfoBox.nuspec
index 7b144c8..c76ae7f 100644
--- a/InfoBox/InfoBox.nuspec
+++ b/InfoBox/InfoBox.nuspec
@@ -2,7 +2,7 @@
InformationBox
- 1.0.0
+ 1.4.0
InformationBox
Johann Blais
Johann Blais
@@ -15,10 +15,11 @@
InformationBox is the simplest and easiest way to create personalized MessageBox.
Stop wasting time developing your own custom MessageBox, everything you need is already available. Just customize your MessageBox using the visual designer and the code is automatically generated !
- InformationBox (.NET 4.0+) is a flexible alternative to the default MessageBox included in the System.Windows.Forms namespace
+ InformationBox (.NET 4.8+, dotnet core 8.0+) is a flexible alternative to the default MessageBox included in the System.Windows.Forms namespace
- - Removed support for .NET 6.0 (Windows)
- - Added support for .NET 10.0 (Windows)
+ - Improved text measurement accuracy by migrating from Graphics.MeasureString (GDI+) to TextRenderer.MeasureText (GDI)
+ - Removed Graphics dependency for better testability
+ - Text sizing now matches actual TextBox rendering more accurately
Copyright 2026
en-US
diff --git a/InfoBox/Properties/AssemblyInfo.cs b/InfoBox/Properties/AssemblyInfo.cs
index a4fbf4f..ab7ac56 100644
--- a/InfoBox/Properties/AssemblyInfo.cs
+++ b/InfoBox/Properties/AssemblyInfo.cs
@@ -42,11 +42,11 @@
// Version information for an assembly consists of the following four values:
//
// Major Version
-// Minor Version
+// Minor Version
// Build Number
// Revision
//
-// You can specify all the values or you can default the Revision and Build Numbers
+// You can specify all the values or you can default the Revision and Build Numbers
// by using the '*' as shown below:
-[assembly: AssemblyVersion("1.3.0.0")]
-[assembly: AssemblyFileVersion("1.3.0.0")]
+[assembly: AssemblyVersion("1.4.0.0")]
+[assembly: AssemblyFileVersion("1.4.0.0")]
diff --git a/README.md b/README.md
index 8ab6d07..a5621dc 100644
--- a/README.md
+++ b/README.md
@@ -2,7 +2,7 @@
.NET 2.0/3.5: [https://nuget.org/packages/InformationBoxLegacy/](https://nuget.org/packages/InformationBoxLegacy/)
-.NET 4.8/.NET 7.0-10.0: [https://nuget.org/packages/InformationBox/](https://nuget.org/packages/InformationBox/)
+.NET 4.8 / dotnet core 8.0-10.0: [https://nuget.org/packages/InformationBox/](https://nuget.org/packages/InformationBox/)
**Build**
@@ -19,7 +19,7 @@ InformationBox is the simplest and easiest way to create personalized MessageBox
Stop wasting time developing your own custom MessageBox, everything you need is already available. Just customize your MessageBox using the visual designer and the code is automatically generated !
-**Find out more about the inner working of InformationBox [in the documentation](https://github.com/JohannBlais/InformationBox/wiki)**.
+**Find out more about the inner working of InformationBox [in the documentation](Documentation)**.
**Highlights**
@@ -35,11 +35,12 @@ It is not planned to implement the new visual style in the .NET 1.1 branch, and
The project is available on NuGet, deployable using the installers, or compilable from source.
**Features**
-* Multilanguage support (contributors needed).
+* Multilanguage support (contributors needed). [Here]() is a list of supported languages.
* New visual style using glass components (.NET 2.0+ only).
* Scrollable when the text is too large.
* Message is selectable for easy copy (Ctrl-C).
* Possibility to modify the colors (back colors).
+* Possibility to change the font and color of the content.
* Auto closing after _n_ seconds.
* Pretty icons included as replacements for the old MessageBox icons.
* Many new icons added to the default ones.
@@ -53,13 +54,14 @@ The project is available on NuGet, deployable using the installers, or compilabl
* Support for MessageBox enums.
* Support for .NET 1.1 (discontinued legacy package)
* Support for .NET 4.8
-* Support for .NET 6.0 (windows)
-* Support for .NET 7.0 (windows)
* Support for .NET 8.0 (windows)
+* Support for .NET 9.0 (windows)
+* Support for .NET 10.0 (windows)
* Help file support.
-* Possibility to show modeless boxes.
-* Possibility to define scopes.
+* Possibility to show modeless boxes, details [here]().
+* Possibility to define [scopes]().
* Opacity (10 to 100%)
* Developer friendly (provide-only-what-you-want-to-customize constructor).
* Visual Designer. Customize your InformationBox and the designer generates the code!
* Available for FREE even for commercial use.
+