diff --git a/Terminal.Gui/Dialogs/MessageBox.cs b/Terminal.Gui/Dialogs/MessageBox.cs
index 5fa9edb4d..e038bf757 100644
--- a/Terminal.Gui/Dialogs/MessageBox.cs
+++ b/Terminal.Gui/Dialogs/MessageBox.cs
@@ -52,7 +52,7 @@ namespace Terminal.Gui {
static int QueryFull (bool useErrorColors, int width, int height, string title, string message, params string [] buttons)
{
- int lines = Label.MeasureLines (message, width);
+ int textWidth = Label.MaxWidth (message, width);
int clicked = -1, count = 0;
var d = new Dialog (title, width, height);
@@ -69,7 +69,7 @@ namespace Terminal.Gui {
d.AddButton (b);
}
if (message != null) {
- var l = new Label ((width - 4 - message.Length) / 2, 0, message);
+ var l = new Label ((width - 4 - textWidth) / 2, 0, message);
d.Add (l);
}
diff --git a/Terminal.Gui/Views/Label.cs b/Terminal.Gui/Views/Label.cs
index 6ebf1978a..21ebd1e86 100644
--- a/Terminal.Gui/Views/Label.cs
+++ b/Terminal.Gui/Views/Label.cs
@@ -209,6 +209,19 @@ namespace Terminal.Gui {
return result.Count;
}
+ ///
+ /// Computes the the max width of a line or multilines needed to render by the Label control
+ ///
+ /// Max width of lines.
+ /// Text, may contain newlines.
+ /// The width for the text.
+ public static int MaxWidth(ustring text, int width)
+ {
+ var result = new List();
+ Recalc(text, result, width, TextAlignment.Left);
+ return result.Max(s => s.RuneCount);
+ }
+
///
/// The text displayed by this widget.
///