Skip to content

Commit 8cf3bf5

Browse files
Use TextRenderer.MeasureText instead of Graphics.MeasureString to get exact result
1 parent 762a771 commit 8cf3bf5

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

ILSpy/Controls/CustomDialog.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,8 @@ public CustomDialog(string caption, string message, int acceptButton, int cancel
5151

5252
using (Graphics g = this.CreateGraphics())
5353
{
54-
Rectangle screen = Screen.PrimaryScreen.WorkingArea;
55-
SizeF size = g.MeasureString(message, label.Font, screen.Width - 20);
56-
Size clientSize = new Size((int)(size.Width * 96 / g.DpiX), (int)(size.Height * 96 / g.DpiY));
54+
SizeF size = TextRenderer.MeasureText(message, label.Font);
55+
Size clientSize = new Size((int)(size.Width * 96 / g.DpiX) + DockPadding.Left + DockPadding.Right, (int)(size.Height * 96 / g.DpiY) + DockPadding.Top + DockPadding.Bottom);
5756
Button[] buttons = new Button[buttonLabels.Length];
5857
int[] positions = new int[buttonLabels.Length];
5958
int pos = 0;

0 commit comments

Comments
 (0)