2

我正在开发具有多显示器功能的每显示器 DPI 感知应用程序。如果窗体在监视器之间移动,则必须知道窗体的设计时 PixelsPerInch 以根据当前监视器 DPI 对其进行缩放。问题是我没有始终如一地得到 PixelsPerInch。在调试时,在表单的重写 Loaded 方法中,我得到了正确的 120 值。独立运行时,我得到 96(因此表格会更大)。我使用 Scaled 属性作为 false 并在 DoShow 中使用 ChangeScale 手动重新缩放(如有必要,还设置监视器索引/boundsrect)。然后在 WM_DPICHANGED 上,如果有的话,再次重新缩放(无论如何它在调试时不会发送,可能是因为 IDE)。一切看起来都很好,只是在独立运行时它更大。

为什么我得到不同的 PixelsPerInch 数字?或者我应该在什么时候请求它的设计时值?

我目前正在使用 XE7。使用标准 (?) win 10 清单,并在单元初始化的最开始调用 SetProcessDPIAwareness。我更喜欢这种方式,因此模糊窗口缩放也可以运行“/no_dpi_aware”。当然我可以硬编码“120”,但我不喜欢它。

<?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>
4

0 回答 0