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

Nick Charnock 1 Reputation point
2021-06-24T17:17:18.353+00:00

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.

Developer technologies | Windows Forms
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Daniel Zhang-MSFT 9,656 Reputation points
    2021-06-25T02:27:52.567+00:00

    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.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.