Skip to content

Commit

Permalink
Merge pull request icsharpcode#3348 from CreateAndInject/FixHighDpi
Browse files Browse the repository at this point in the history
Fix high Dpi, close icsharpcode#3347
  • Loading branch information
siegfriedpammer authored Dec 15, 2024
2 parents 663dea4 + 19d4f01 commit 51aac5f
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions ILSpy/Controls/CustomDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,8 @@ public CustomDialog(string caption, string message, int acceptButton, int cancel

using (Graphics g = this.CreateGraphics())
{
Rectangle screen = Screen.PrimaryScreen.WorkingArea;
SizeF size = g.MeasureString(message, label.Font, screen.Width - 20);
Size clientSize = size.ToSize();
SizeF size = TextRenderer.MeasureText(message, label.Font);
Size clientSize = new Size((int)(size.Width * 96 / g.DpiX) + DockPadding.Left + DockPadding.Right, (int)(size.Height * 96 / g.DpiY) + DockPadding.Top + DockPadding.Bottom);
Button[] buttons = new Button[buttonLabels.Length];
int[] positions = new int[buttonLabels.Length];
int pos = 0;
Expand All @@ -65,8 +64,8 @@ public CustomDialog(string caption, string message, int acceptButton, int cancel
string buttonLabel = buttonLabels[i];
newButton.Text = buttonLabel;
newButton.Click += new EventHandler(ButtonClick);
SizeF buttonSize = g.MeasureString(buttonLabel, newButton.Font);
newButton.Width = Math.Max(newButton.Width, ((int)Math.Ceiling(buttonSize.Width / 8.0) + 1) * 8);
SizeF buttonSize = TextRenderer.MeasureText(buttonLabel, newButton.Font);
newButton.Width = Math.Max(newButton.Width, ((int)Math.Ceiling(buttonSize.Width * 96 / g.DpiX / 8.0) + 1) * 8);
positions[i] = pos;
buttons[i] = newButton;
pos += newButton.Width + 4;
Expand Down

0 comments on commit 51aac5f

Please sign in to comment.