1

Can someone explain this strange phenomenon?

Created a Winforms application .NETFramework 4.7.

this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;

Created a panel and set its location left, top to: 100, and its size width, height to: 100.

And as per here

  1. Created the app.manifest and enabled Windows 10 compatibility
  2. Created the app.config and changed the value="PerMonitorV2" to Unaware, System, PerMonitor, then PerMonitorV2.
<System.Windows.Forms.ApplicationConfigurationSection>
    <!--<add key="DpiAwareness" value="Unaware"/>-->
    <add key="DpiAwareness" value="System"/>
    <!--<add key="DpiAwareness" value="PerMonitor"/>-->
    <!--<add key="DpiAwareness" value="PerMonitorV2"/>-->
</System.Windows.Forms.ApplicationConfigurationSection>

Then for each awareness change, I did change my primary screen DPI scaling from 100% to 175. I run the application each time logging the panel location and its size after InitializeComponent();

Here are the results:

Awareness: Unaware  
DPI:  96 (100%) -> Left: 100, Width: 100, Top: 100, Height: 100    
DPI: 120 (125%) -> Left: 100, Width: 100, Top: 100, Height: 100    
DPI: 144 (150%) -> Left: 100, Width: 100, Top: 100, Height: 100    
DPI: 168 (175%) -> Left: 100, Width: 100, Top: 100, Height: 100  

Awareness: System Aware  
DPI:  96 (100%) -> Left: 100, Width: 100, Top: 100, Height: 100    
DPI: 120 (125%) -> Left: 133, Width: 133, Top: 123, Height: 123 ?!    
DPI: 144 (150%) -> Left: 150, Width: 150, Top: 154, Height: 154 ?!    
DPI: 168 (175%) -> Left: 183, Width: 183, Top: 185, Height: 185 ?!   

Awareness: Per-Monitor Aware  
DPI:  96 (100%) -> Left: 100, Width: 100, Top: 100, Height: 100    
DPI: 120 (125%) -> Left: 100, Width: 100, Top: 100, Height: 100    
DPI: 144 (150%) -> Left: 100, Width: 100, Top: 100, Height: 100    
DPI: 168 (175%) -> Left: 100, Width: 100, Top: 100, Height: 100  

Awareness: Per-Monitor Aware v2  
DPI:  96 (100%) -> Left: 100, Width: 100, Top: 100, Height: 100    
DPI: 120 (125%) -> Left: 100, Width: 100, Top: 100, Height: 100    
DPI: 144 (150%) -> Left: 100, Width: 100, Top: 100, Height: 100    
DPI: 168 (175%) -> Left: 100, Width: 100, Top: 100, Height: 100   

Does someone have any idea or knowledge to explain the strange behavior in the case of (Awareness: System Aware, 125%, 150%, 175%)?

Edit
In case of 125% I do not understand where 133, 123 comes from. In case of 150% there seams to be some logic but not for 154. Also in 175% I can not put any logic.

  • The System performs the scaling for you. Test with `EnableWindowsFormsHighDpiAutoResizing` set to `true` and `false` and of course with `AutoScaleMode = Dpi`. Remove that `AutoScaleDimensions` from the Designer file if it doesn't go away on its own when you change `AutoScaleMode` (it probably won't :). – Jimi Oct 16 '20 at 16:32
  • I see, but in case of 125% why 133 on not 125 and why 123? Why left, width are the same and why top, height differ from them. In case of 150% there seams to be some logic. – Ervin Gegprifti Oct 17 '20 at 19:38
  • You're scaling based on the Font dimensions, not on the DPI value. The actual percentage increase is determined by multiple factors, including the Font used, of course, the `AutoSize` setting of the containers: e.g., a Panel may contain Buttons or TextBoxes; these two controls may scale differently depending on the Font in use and whether the Font is the same for all, also slightly different if the Font is inherited from the Parent container or it's set explicitly. It's a relatively complex calculation. You may want to scale on DPI, handle scale events, make use auto-sizing containers... – Jimi Oct 17 '20 at 21:16

0 Answers0