■ 화면 배율 계수를 설정하는 방법을 보여준다.
▶ 예제 코드 (C#)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
using System; using System.Drawing; using System.Runtime.InteropServices; #region 화면 배율 계수 설정하기 - GetScreenScalingFactor() /// <summary> /// 화면 배율 계수 설정하기 /// </summary> /// <returns>배율 계수</returns> public float GetScreenScalingFactor() { Graphics graphics = Graphics.FromHwnd(IntPtr.Zero); IntPtr deviceHandle = graphics.GetHdc(); int PhysicalScreenHeight = GetDeviceCaps(deviceHandle, 117); int LogicalScreenHeight = GetDeviceCaps(deviceHandle, 10 ); float scalingFactor = (float)PhysicalScreenHeight / (float)LogicalScreenHeight; return scalingFactor; // 1.25 = 125% } #endregion #region 장치 정보 구하기 - GetDeviceCaps(deviceContextHandle, index) /// <summary> /// 장치 정보 구하기 /// </summary> /// <param name="deviceContextHandle">디바이스 컨텍스트 핸들</param> /// <param name="index">인덱스</param> /// <returns>장치 정보</returns> [DllImport("gdi32")] private static extern int GetDeviceCaps(IntPtr deviceContextHandle, int index); #endregion |