첨부 실행 코드는 나눔고딕코딩 폰트를 사용합니다.
728x90
반응형
728x170
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
728x90
반응형
그리드형(광고전용)
Posted by icodebroker

댓글을 달아 주세요