如何获取下图中的125%呢?

获取Windows DPI

 

 [DllImport("gdi32.dll")]
        static extern int GetDeviceCaps(IntPtr hdc, int nIndex);
        public enum DeviceCap
        {
            VERTRES = 10,
            DESKTOPVERTRES = 117,

            // http://pinvoke.net/default.aspx/gdi32/GetDeviceCaps.html
        }


        private float GetScalingFactor()
        {
            Graphics g = Graphics.FromHwnd(IntPtr.Zero);
            IntPtr desktop = g.GetHdc();
            int LogicalScreenHeight = GetDeviceCaps(desktop, (int)DeviceCap.VERTRES);
            int PhysicalScreenHeight = GetDeviceCaps(desktop, (int)DeviceCap.DESKTOPVERTRES);

            float ScreenScalingFactor = (float)PhysicalScreenHeight / (float)LogicalScreenHeight;

            return ScreenScalingFactor; // 1.25 = 125%
        }

 

相关文章:

  • 2021-12-04
  • 2021-11-02
  • 2021-11-20
  • 2021-11-14
  • 2022-01-14
  • 2021-12-15
  • 2021-12-04
  • 2022-01-06
猜你喜欢
  • 2021-10-19
  • 2021-10-19
  • 2021-11-20
  • 2021-05-06
  • 2021-09-06
  • 2021-10-17
  • 2021-11-05
  • 2021-10-18
相关资源
相似解决方案