Notice: This website is an unofficial Microsoft Knowledge Base (hereinafter KB) archive and is intended to provide a reliable access to deleted content from Microsoft KB. All KB articles are owned by Microsoft Corporation. Read full disclaimer for more details.

Unusual scaling for some Windows Forms applications with the .NET Framework 4.5.2


Symptoms

Windows Forms applications that implement their own scaling logic for high DPI settings may encounter unusual scaling if these applications are opted into the Microsoft .NET Framework 4.5.2 High DPI changes by using the following .config file setting:
<appSettings>

<add key="EnableWindowsFormsHighDpiAutoResizing" value="true" />

</appSettings>

↑ Back to the top


Resolution

Applications that apply a scaling factor on top of the scaled value will encounter extra scaling when they are opted into the .NET Framework 4.5.2 High DPI improvements. To resolve this issue, update the application’s scaling logic to apply scaling on the ToolStrip.ImageScalingSize default value. This change will avoid the introduction of extra scaling. 

For example, applications that have the following code will scale ToolStrip buttons twice:
public MyToolStrip()

{

IntPtr hDC = GetDC(new HandleRef(null, IntPtr.Zero));

double xFactor = GetDeviceCaps(new HandleRef(null, hDC), LOGPIXELSX) / 96.0;

double yFactor = GetDeviceCaps(new HandleRef(null, hDC), LOGPIXELSY) / 96.0;

this.ImageScalingSize = new Size((int)(this.ImageScalingSize.Width * xFactor), (int)(this.ImageScalingSize.Height * yFactor));

InitializeComponent();

}

You can use the following code to scale from the constant default size, or from your desired image size:
this.ImageScalingSize = new Size((int)(16 * xFactor), (int)(16 * yFactor));

  

↑ Back to the top


Keywords: kbtshoot, kbexpertiseinter, kbsurveynew, kb

↑ Back to the top

Article Info
Article ID : 2971001
Revision : 1
Created on : 1/7/2017
Published on : 5/29/2014
Exists online : False
Views : 203