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 when custom Font is used

See original GitHub issue
  • .NET Core Version: 6.0, 7.0/main

  • Have you experienced this same bug with .NET Framework?: No (also works in .NET 5)

Problem description:

This is variation of problem reported in #6152 with the twist of setting Font on one of the controls. It is a regression from .NET 5.

Expected behavior:

ScaleControl is called consistently when moving window to display with different DPI.

Minimal repro:

WinFormsApp3.zip

Same repro steps as #6152. The difference is that a custom font is set on one of the UserControls.

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
filipnavaracommented, Nov 18, 2021

So, our Font got disposed from here when the main window was moved to secondary screen: https://github.com/dotnet/winforms/blob/29e805d6d3e60144a31dad96d848cdcfe454e4eb/src/System.Windows.Forms/src/System/Windows/Forms/Control.cs#L12278-L12282

 	System.Drawing.Common.dll!System.Drawing.Font.Dispose() Line 171	C#
>	System.Windows.Forms.dll!System.Windows.Forms.Control.WmDpiChangedBeforeParent(ref System.Windows.Forms.Message m) Line 12349	C#
 	System.Windows.Forms.dll!System.Windows.Forms.Control.WndProc(ref System.Windows.Forms.Message m) Line 13306	C#
 	System.Windows.Forms.dll!System.Windows.Forms.ScrollableControl.WndProc(ref System.Windows.Forms.Message m) Line 1507	C#
 	System.Windows.Forms.dll!System.Windows.Forms.ContainerControl.WndProc(ref System.Windows.Forms.Message m) Line 2093	C#
 	System.Windows.Forms.dll!System.Windows.Forms.UserControl.WndProc(ref System.Windows.Forms.Message m) Line 336	C#
 	MailClient.Common.UI.dll!MailClient.Common.UI.Controls.AutomationViewUserControl.WndProc(ref System.Windows.Forms.Message m) Line 70	C#
 	System.Windows.Forms.dll!System.Windows.Forms.Control.ControlNativeWindow.OnMessage(ref System.Windows.Forms.Message m) Line 68	C#
 	System.Windows.Forms.dll!System.Windows.Forms.Control.ControlNativeWindow.WndProc(ref System.Windows.Forms.Message m) Line 122	C#
 	System.Windows.Forms.dll!System.Windows.Forms.NativeWindow.Callback(System.IntPtr hWnd, Interop.User32.WM msg, System.IntPtr wparam, System.IntPtr lparam) Line 370	C#
 	[Native to Managed Transition]	
 	[Managed to Native Transition]	
 	System.Windows.Forms.dll!System.Windows.Forms.NativeWindow.DefWndProc(ref System.Windows.Forms.Message m) Line 516	C#
 	System.Windows.Forms.dll!System.Windows.Forms.Form.DefWndProc(ref System.Windows.Forms.Message m) Line 3289	C#
 	System.Windows.Forms.dll!System.Windows.Forms.Control.WndProc(ref System.Windows.Forms.Message m) Line 13149	C#
 	System.Windows.Forms.dll!System.Windows.Forms.ScrollableControl.WndProc(ref System.Windows.Forms.Message m) Line 1507	C#
 	System.Windows.Forms.dll!System.Windows.Forms.ContainerControl.WndProc(ref System.Windows.Forms.Message m) Line 2093	C#
 	System.Windows.Forms.dll!System.Windows.Forms.Form.WmSysCommand(ref System.Windows.Forms.Message m) Line 6495	C#
 	System.Windows.Forms.dll!System.Windows.Forms.Form.WndProc(ref System.Windows.Forms.Message m) Line 6595	C#
 	MailClient.Common.UI.dll!MailClient.Common.UI.Forms.ThemeForm.WndProc(ref System.Windows.Forms.Message m) Line 166	C#
 	MailClient.Common.UI.dll!MailClient.Common.UI.Forms.BorderlessForm.WndProc(ref System.Windows.Forms.Message m) Line 1013	C#
 	MailClient.dll!MailClient.UI.Forms.BorderlessBaseFormWithToolbar.WndProc(ref System.Windows.Forms.Message m) Line 73	C#
 	MailClient.dll!MailClient.UI.Forms.formMain.WndProc(ref System.Windows.Forms.Message m) Line 854	C#
1reaction
kirsan31commented, Nov 12, 2021
Read more comments on GitHub >

github_iconTop Results From Across the Web

Setting a font form disables autoscaling · Issue #6151
Problem description: Forms with an explicitly set font do not automatically scale on font/DPI size changes. The AutoScaleDimensions property is ...
Read more >
Per-Monitor V2 DPI awareness in WinForms not rescaling ...
The test application rescales as the DPI changes. Here is my problem: The legacy software contains a lot of custom fonts on each...
Read more >
Fix DPI display issues in Windows Form Designer - Visual ...
Without proper scaling, user interface (UI) elements and text are too tiny to use effectively and can overlap. To help remedy this issue, ......
Read more >
WinForms Scaling at Large DPI Settings–Is It Even Possible?
Microsoft added some support for GDI/GDI+ scaling recently. It does not work flawlessly—it generally scales fonts and some graphics.
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