question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

PerMonitorV2 DPI scaling not firing ScaleControl method for deeply nested layouts

See original GitHub issue
  • .NET Core Version: 6.0 RTM

  • Have you experienced this same bug with .NET Framework?: No

Problem description:

Deeply nested controls don’t get ScaleControl called when moving to secondary monitor (150% DPI -> 100% DPI) in PerMonitorV2 mode.

Expected behavior:

ScaleControl is always called for deeply nested controls when DPI changes.

Minimal repro:

To be done.

It looks like the following code may be to blame: https://github.com/dotnet/winforms/blob/83b3228c2fa5bbde44cb1e8e1b36eb6f328f1289/src/System.Windows.Forms/src/System/Windows/Forms/ContainerControl.cs#L688-L697

When reaching one of the deeply nested container controls it looks up the parent and gets the scale factor from it. However, the parent itself at this point has AutoScaleMode.Inherit and hence the values are not set and the reported scaling is (1.0F, 1.0F). That leads to the following code skipping the scaling:

https://github.com/dotnet/winforms/blob/83b3228c2fa5bbde44cb1e8e1b36eb6f328f1289/src/System.Windows.Forms/src/System/Windows/Forms/ContainerControl.cs#L990-L1000

Values in debugger:

image

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:14 (12 by maintainers)

github_iconTop GitHub Comments

1reaction
dreddy-workcommented, Nov 10, 2021

Note that there’s a similar IsScaledByParent method introduced in the same commit which is likely correct

That method was checking if parent hierarchy has a Container that could lead to scaling children. Given that it was not looking for which parent Container, that should be good.

1reaction
kirsan31commented, Nov 10, 2021

https://github.com/dotnet/winforms/pull/6130? Seems need to be servicing…

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to write WinForms code that auto-scales to system font ...
I found it to be very hard to get WinForms to play nice with high DPI. So, I wrote a VB.NET method to...
Read more >
Windows 11, PerMonitorV2 is NOT automatically scaling ...
The documentation claims this setting automatically scales non-client areas of my window. However it does not. On my 4K monitor the non-client ...
Read more >
HDPI support in .NET
WinForms HighDPI PerMonitorV2 ListView ColumnHeader scales wrong #5090 ... [Multi-Monitor] DataGridView is not scaled well when DPIs differ ...
Read more >
WinForms Scaling at Large DPI Settings–Is It Even Possible?
A static method in .NET Core 3.0/.NET5 for Windows Forms. Manifest File. The most common way to declare an application as DPI aware...
Read more >
Inner details of DPI scaling in Office COM add-ins
In the WndProc method of the form class, the add-in handles the WM_DPICHANGED message to retrieve the form size and the DPI to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found