Skip to content

Fix per-monitor DPI scaling and related layout regressions - #66

Open
mojingjing-git wants to merge 1 commit into
lukaslangrock:masterfrom
mojingjing-git:fix/per-monitor-v2-layout
Open

mojingjing-git wants to merge 1 commit into
lukaslangrock:masterfrom
mojingjing-git:fix/per-monitor-v2-layout

Conversation

@mojingjing-git

Copy link
Copy Markdown

My earlier claim that “the old version would inevitably get stretched and misaligned at 175%” was too strong. The original version just runs at the system DPI at startup, and it gets blurry when moved across monitors with different scaling. So my earlier change doesn’t prove the old version was wrong—it only shows the cross-monitor blurriness. That means those few lines I temporarily added really weren’t necessary.

Later, I use GPT-6 to dig into this.

The final fix is roughly this:

  • Turn on real per-monitor DPI scaling. App.config was already requesting PerMonitorV2, but the old declaration in app.manifest was overriding it. I removed the old declaration and unified the scaling mode of the four forms—Menu, Settings, InputBox, and Countdown—to Dpi, with design sizes based on 96 DPI. That way, when a form moves across monitors, WinForms adjusts the controls to the target monitor’s DPI.
  • Give auto-scaled controls enough room. Scaling changes control positions and sizes. Several right-aligned links in Settings were using both AutoSize and right anchoring; in testing, they ran outside the container or covered other text. I gave them fixed widths, kept right anchoring and right alignment, and adjusted the spacing between title sections. In the About group, I removed bottom anchoring, since it doesn’t work well for fixed-size forms. For InputBox, I measure how much height the current hint text needs and enlarge the window if needed; the countdown digit area gets repositioned after the first DPI sync, while keeping its anchors for window resizing. The actual layout changes are in Settings.Designer.cs, InputBox.cs, and a few other files.
  • Cover the mismatch when a form is first opened on a secondary monitor. Testing showed that when some forms are first created on a secondary monitor, the DPI reported by the Windows window handle doesn’t match WinForms’ DeviceDpi. The newly added DpiScaling.cs checks both values first; if they match, it does nothing. If they don’t, it sends WM_DPICHANGED to update WinForms’ scaling state, then adjusts the fonts explicitly set in the designer according to the DPI ratio.

Let the existing PerMonitorV2 app configuration take effect and use DPI
autoscaling consistently. Keep right-aligned Settings text within its
allocated rows, preserve the hidden About layout, and size InputBox text
to fit its content.

Synchronize a newly opened form when native and WinForms DPI values differ,
including explicit fonts, and retain the countdown clock's resize anchors.

AI-Assistance: OpenAI Codex (implementation and local validation)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant