2

I'm working on a per-monitor DPI aware application with multi-monitor capability. It's necessary to know the design-time PixelsPerInch of the Form to scale it according to the current monitor DPI if the Form is moved across monitors. The problem is that I don't get PixelsPerInch consistently. While debugging, in the form's overridden Loaded method I get the correct 120 value. When running standalone, I get 96 (and so the form scales bigger). I use Scaled property as false and rescale manually in DoShow with ChangeScale (also setting monitor index/boundsrect if necessary). Then on WM_DPICHANGED, if ever, rescale again (anyway it's not sent while debugging, probably because of the IDE). All looks fine, just on standalone run it's larger.

Why do I get different numbers for PixelsPerInch? Or at which point should I request the design-time value of it?

I'm using XE7 at the moment. With a standard (?) win 10 manifest, and call SetProcessDPIAwareness at the very beginning of unit initializations. I prefer it this way, so a "/no_dpi_aware" run is also possible with the blurry windows scaling. Of course I can just hardcode "120", but I wouldn't like it.

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
  <assemblyIdentity type="win32" name="xxxx" version="3.1.0.0" processorArchitecture="*"/>
  <dependency>
    <dependentAssembly>
      <assemblyIdentity type="win32" name="Microsoft.Windows.Common-Controls" version="6.0.0.0" publicKeyToken="6595b64144ccf1df" language="*" processorArchitecture="*"/>
    </dependentAssembly>
  </dependency>
  <trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
    <security>
      <requestedPrivileges>
        <requestedExecutionLevel level="asInvoker"/>
        </requestedPrivileges>
    </security>
  </trustInfo>
  <compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
   <application>
      <!--The ID below indicates application support for Windows 10 -->
      <supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}"/>     
      <!--The ID below indicates application support for Windows 8.1 -->
      <supportedOS Id="{1f676c76-80e1-4239-95bb-83d0f6d0da78}"/>
      <!--The ID below indicates application support for Windows 8 -->
      <supportedOS Id="{4a2f28e3-53b9-4441-ba9c-d69d4a4a6e38}"/>
      <!--The ID below indicates application support for Windows 7 -->
      <supportedOS Id="{35138b9a-5d96-4fbd-8e2d-a2440225f93a}"/>
      <!--The ID below indicates application support for Windows Vista -->
      <supportedOS Id="{e2011457-1546-43c5-a5fe-008deee3d3f0}"/>
    </application>
  </compatibility> 
</assembly>
kgz
  • 527
  • 2
  • 10

0 Answers0