FormsMap Control and HighDPI settings

Within this forum we want to offer discussions all around our .NET based Map control including all .Net-language specific questions concerning calls of the xServer-API. Attention: xServer-relevant concepts can be found in further forums such as xRoute or xTour.
Post Reply
User avatar
Oliver Heilig
Posts: 160
Joined: Tue May 13, 2014 12:10 pm
Location: Karlsruhe, Germany
Contact:

FormsMap Control and HighDPI settings

Post 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
Oliver Heilig
Chief Developer Logistic Services
PTV GROUP - Germany

https://github.com/oliverheilig/
Post Reply