Dpi Aware

作者: 雪之梦_8f14 | 来源:发表于2019-07-22 18:12 被阅读0次

    设置

     <application xmlns="urn:schemas-microsoft-com:asm.v3">
        <windowsSettings>
          <!--<dpiAwareness xmlns="http://schemas.microsoft.com/SMI/2016/WindowsSettings">PerMonitor</dpiAwareness>-->
          <dpiAware xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">true/pm</dpiAware>
        </windowsSettings>
      </application>
    
    

    获取虚拟屏幕的尺寸的三种方式

    通过api获取

    int left = GetSystemMetrics(SM_XVIRTUALSCREEN);
    int top = GetSystemMetrics(SM_YVIRTUALSCREEN);
    int width = GetSystemMetrics(SM_CXVIRTUALSCREEN);
    int height = GetSystemMetrics(SM_CYVIRTUALSCREEN);
    

    通过winform获取

    int width3 = SystemInformation.VirtualScreen.Width;
    int height3 = SystemInformation.VirtualScreen.Height;
    

    通过wpf获取

    double height1 = SystemParameters.VirtualScreenHeight;
    double width1 = SystemParameters.VirtualScreenWidth;
    

    • dpi不为100%时, 当没有设置 以下代码的时候,不管是通过api,还是通过winform、wpf获取到的虚拟屏幕的高度都不正确, 所以必须设置以下代码
      <dpiAware xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">true/pm</dpiAware> </windowsSettings>

    相关文章

      网友评论

          本文标题:Dpi Aware

          本文链接:https://www.haomeiwen.com/subject/xmxglctx.html