Page 1 of 1

FormsMap Control and HighDPI settings

Posted: Mon Dec 11, 2017 3:12 pm
by Oliver Heilig
Hi,

some customers have reported issues with the xServer.NET FormMap control and HighDPI displays. Whenever the Map is displayed, the complete application gets scaled weirdly. I've digged into this issue and found that this can be reproduced simply by adding the Standard WinForms ElementHost-Control to the application. This control used to host the internal Map (which is based on WPF).

I could resolve this issue by making the main application DPI-aware, these two methods both worked for me:
  1. Add an manifest for the application, by "Add new Item" -> "Application Manifest File". Then a manifest file is created where you can add a dpiAware section. You can just remove the comment in the created app.manifest file:

    Code: Select all

    <assembly>
    ...
      <!-- Indicates that the application is DPI-aware and will not be automatically scaled by Windows at higher
           DPIs. Windows Presentation Foundation (WPF) applications are automatically DPI-aware and do not need 
           to opt in. Windows Forms applications targeting .NET Framework 4.6 that opt into this setting, should 
           also set the 'EnableWindowsFormsHighDpiAutoResizing' setting to 'true' in their app.config. -->
      <application xmlns="urn:schemas-microsoft-com:asm.v3">
        <windowsSettings>
          <dpiAware xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">true</dpiAware>
        </windowsSettings>
      </application>
    </assembly>
  2. Another method is to call the function SetProcessDPIAware() in your Main() method:

    Code: Select all

    [STAThread]
        static void Main() {
            if (Environment.OSVersion.Version.Major >= 6) 
                SetProcessDPIAware();
    ...
        }
    
        [System.Runtime.InteropServices.DllImport("user32.dll")]
        private static extern bool SetProcessDPIAware();
I hope this resolves these issues for your application. You can find the stackoverflow thread about this topic here:
https://stackoverflow.com/questions/132 ... -setting-e

Regards
Oli