Skip to content

Commit 51aac5f

Browse files
Merge pull request #3348 from CreateAndInject/FixHighDpi
Fix high Dpi, close #3347
2 parents 663dea4 + 19d4f01 commit 51aac5f

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

ILSpy/Controls/CustomDialog.cs

Lines changed: 4 additions & 5 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 = size.ToSize();
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;
@@ -65,8 +64,8 @@ public CustomDialog(string caption, string message, int acceptButton, int cancel
6564
string buttonLabel = buttonLabels[i];
6665
newButton.Text = buttonLabel;
6766
newButton.Click += new EventHandler(ButtonClick);
68-
SizeF buttonSize = g.MeasureString(buttonLabel, newButton.Font);
69-
newButton.Width = Math.Max(newButton.Width, ((int)Math.Ceiling(buttonSize.Width / 8.0) + 1) * 8);
67+
SizeF buttonSize = TextRenderer.MeasureText(buttonLabel, newButton.Font);
68+
newButton.Width = Math.Max(newButton.Width, ((int)Math.Ceiling(buttonSize.Width * 96 / g.DpiX / 8.0) + 1) * 8);
7069
positions[i] = pos;
7170
buttons[i] = newButton;
7271
pos += newButton.Width + 4;

0 commit comments

Comments
 (0)