question

NickCharnock-0089 avatar image
0 Votes"
NickCharnock-0089 asked NickCharnock-0089 commented

Issues with per-monitor DPI aware WinForms .Net 4.8 app

Issues only happen when you've got a multi screen setup and have different scaling on each screen. In the example here my main display is 100% scaling and I drag it to my laptops screen at 225%.

Issue 1 is dragging an MDI form from main display to laptop, here's what it looks like on main:

109075-screenshot-2021-06-24-173609.png

Everything looks fine. Then I drag it to laptop screen and I get this:

109047-screenshot-2021-06-24-173741.png

If I close and re-open the form on the laptop screen I get this:

109059-screenshot-2021-06-24-173843.png

It looks like the MDI parent knows what the scaling is and works fine, but the MID child seems to think the scaling is still 100% and doesn't render correctly, even if you close and re-open.

Issue 2 affects any form that has its window position as centre parent

This is what it looks like when I open it on my main display (All good):

109151-screenshot-2021-06-24-174037.png

And this is what it looks like if I open it on my laptop screen (Note if I open it on my main display and then drag it to the laptop screen it renders fine):

109090-screenshot-2021-06-24-180801.png

So in this scenario, the form mostly thinks the scaling is 100% apart from things like the toolstrip control which seems to know it really is 225%.

Are these know issues with per monitor aware .Net 4.8 WinForm apps? Or am I missing something in my implementation?

Thanks in advance.

windows-forms
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

DanielZhang-MSFT avatar image
0 Votes"
DanielZhang-MSFT answered NickCharnock-0089 commented

Hi NickCharnock-0089,
According to this document, we can learn that when an application reports to Windows that it wants to run in this mode, Windows does not stretch the application bitmap when the DPI changes, but sends WM_DPICHANGED to the application window. Windows Forms does not support automatic DPI scaling. So it’s recommended to use per-monitor DPI perception mode, so that it will render correctly immediately when the DPI changes。
Enable per-monitor DPI awareness in the app.config file.

 <System.Windows.Forms.ApplicationConfigurationSection>
   <add key="DpiAwareness" value="PerMonitorV2" />
 </System.Windows.Forms.ApplicationConfigurationSection>

Here is a related document you can refer to.
Best Regards,
Daniel Zhang


If the response is helpful, please click "Accept Answer" and upvote it.

Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


· 10
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi Daniel,

We have already implemented 'PerMonitorV2', this works fine for regular pop-up windows but not in the 2 scenarios described in my OP.

Implement as per this article here:

https://docs.microsoft.com/en-us/dotnet/desktop/winforms/high-dpi-support-in-windows-forms?view=netframeworkdesktop-4.8

0 Votes 0 ·

Also, maybe it's not clear from the screen shots, but where the scaling is wrong it's actually rendering at 100% scaling on a 225% display and so small you can't use it.

0 Votes 0 ·

Hi @NickCharnock-0089,
>>So in this scenario, the form mostly thinks the scaling is 100% apart from things like the toolstrip control which seems to know it really is 225%.
Please set your form's autoScaleMode property to Dpi.

  Form1.AutoScaleMode = AutoScaleMode.Dpi;

Here is a related document.
Best Regards,
Daniel Zhang


0 Votes 0 ·

All forms in the project already have their AutoScaleMode set to Dpi.

0 Votes 0 ·
Show more comments