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.

FormsMap Control and HighDPI settings

Postby Oliver Heilig » Mon Dec 11, 2017 3:12 pm

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: xml code
    <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: csharp code
    [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/
User avatar
Oliver Heilig
 
Posts: 122
Joined: Tue May 13, 2014 12:10 pm
Location: Karlsruhe, Germany

Return to PTV xServer.NET (Admin=OH)