DPI Awareness strange behavior per different DPI scale factors

227 views Asked by At

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.

0

There are 0 answers