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
19 changes: 6 additions & 13 deletions InfoBox/Form/InformationBoxForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,6 @@ internal partial class InformationBoxForm : Form
/// </summary>
private readonly string doNotShowAgainText;

/// <summary>
/// Contains the graphics used to measure the strings
/// </summary>
private readonly Graphics measureGraphics;

/// <summary>
/// Contains a reference to the active form
/// </summary>
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -1007,15 +1000,15 @@ 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;
}

// "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.
Expand Down Expand Up @@ -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
{
Expand All @@ -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);
Expand All @@ -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);
}
}

Expand Down Expand Up @@ -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)
Expand Down
9 changes: 5 additions & 4 deletions InfoBox/InfoBox.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<package xmlns="http://schemas.microsoft.com/packaging/2011/08/nuspec.xsd">
<metadata>
<id>InformationBox</id>
<version>1.0.0</version>
<version>1.4.0</version>
<title>InformationBox</title>
<authors>Johann Blais</authors>
<owners>Johann Blais</owners>
Expand All @@ -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 !</description>
<summary>InformationBox (.NET 4.0+) is a flexible alternative to the default MessageBox included in the System.Windows.Forms namespace</summary>
<summary>InformationBox (.NET 4.8+, dotnet core 8.0+) is a flexible alternative to the default MessageBox included in the System.Windows.Forms namespace</summary>
<releaseNotes>
- 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
</releaseNotes>
<copyright>Copyright 2026</copyright>
<language>en-US</language>
Expand Down
8 changes: 4 additions & 4 deletions InfoBox/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
16 changes: 9 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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**

Expand All @@ -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**

Expand All @@ -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](<Supported Languages>) 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.
Expand All @@ -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](<Modeless boxes>).
* Possibility to define [scopes](<InformationBox 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.

Loading