1

A client complained that on his computer, some text on certain forms were showing in the wrong size and clipping out of boundaries.

The text the user complains about are LinkLabel controls.

According to remarks in the documentation, the controls must set UseCompatibleTextRendering to true in order for the correct portion of the text to be highlighted as a link.

I observe that the client uses a High-DPI monitor and display scaling at 125% and as such I suspect this is a Display Scaling issue as other labels have this property set to false and appear OK.

Does anybody know how to get LinkLabel to scale correctly?

Thomas Harris
  • 573
  • 4
  • 14
  • 3
    This link by be more useful. [High DPI support in Windows Forms](https://learn.microsoft.com/en-us/dotnet/framework/winforms/high-dpi-support-in-windows-forms) – ourmandave Mar 11 '20 at 12:34
  • 2
    You didn't read the Remarks section thoroughly enough: *the controls must set UseCompatibleTextRendering* is not what is suggested there. Your app needs to be DpiAware. Set the Form to auto scale to Dpi and do this: [How to configure an app to run correctly on a machine with a high DPI setting (e.g. 150%)?](https://stackoverflow.com/a/13228495/7444103) (some layout redefinition required). – Jimi Mar 11 '20 at 13:36

1 Answers1

0

As I understand from the answers of @ourmandave and @Jimi suggested for the LinkLabel control it seems to be important, that the property UseCompatibleTextRenderin is set to true.

Additionally it is important according to the Microsoft documentation, that the application is dpi aware and the PerMonitorV2 is set.

Microsoft states out, that is important to differentiate between applications that use .NET Framework 4.7 and applications that use a lower version of the .NET Framework.

In my case, I use .NET Framework 4.6.2, it was necessary to add these options to the manifest.

<?xml version="1.0" encoding="utf-8"?>
<assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1" xmlns:asmv3="urn:schemas-microsoft-com:asm.v3">
  <assemblyIdentity version="1.0.0.0" name="demo"/>
  <asmv3:application>
    <asmv3:windowsSettings>
      <dpiAware xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">true</dpiAware>
      <dpiAwareness xmlns="http://schemas.microsoft.com/SMI/2016/WindowsSettings">PerMonitorV2</dpiAwareness>
    </asmv3:windowsSettings>
  </asmv3:application>
  
  <compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
    <application>
      <!-- Windows Vista -->
      <supportedOS Id="{e2011457-1546-43c5-a5fe-008deee3d3f0}" />

      <!-- Windows 7 -->
      <supportedOS Id="{35138b9a-5d96-4fbd-8e2d-a2440225f93a}" />

      <!-- Windows 8 -->
      <supportedOS Id="{4a2f28e3-53b9-4441-ba9c-d69d4a4a6e38}" />

      <!-- Windows 8.1 -->
      <supportedOS Id="{1f676c76-80e1-4239-95bb-83d0f6d0da78}" />

      <!-- Windows 10 -->
      <supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}" />
    </application>
  </compatibility>
</assembly>

In special I had to add the namespace xmlns:asmv3="urn:schemas-microsoft-com:asm.v3" at the top. And the whole block using that namespace:

  <asmv3:application>
    <asmv3:windowsSettings>
      <dpiAware xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">true</dpiAware>
      <dpiAwareness xmlns="http://schemas.microsoft.com/SMI/2016/WindowsSettings">PerMonitorV2</dpiAwareness>
    </asmv3:windowsSettings>
  </asmv3:application>

It seems to be also important to include the Windows 10 Part which was already included in my case.

From .NET Framework 4.7 on, these information should be included in the normal app.config, this must be like

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

For the last part I can't give any guarantee because I haven't tested it so far.

geraphl
  • 305
  • 4
  • 10