Esempio n. 1
0
 static DpiHelper()
 {
     if (DpiHelperMethods.IsSupported)
     {
         DpiMethods.SetProcessDpiAwareness(DpiMethods.ProcessDpiAwareness.DpiHelperAware);
     }
 }
Esempio n. 2
0
        /// <summary>
        /// モニターごとのDPI情報を取得する
        /// </summary>
        /// <param name="mon">モニタハンドル</param>
        /// <returns>DpiScale</returns>
        internal static DpiScale        GetDpiForMonitor(IntPtr mon)
        {
            uint dpiX = 96;
            uint dpiY = 96;

            if (null != mon && DpiHelperMethods.IsSupported)
            {
                DpiMethods.GetDpiForMonitor(mon, MonitorDpiType.Default, ref dpiX, ref dpiY);
            }

            return(new DpiScale(dpiX / 96.0, dpiY / 96.0));
        }
Esempio n. 3
0
        public static Dpi     GetDpi(this HwndSource hwndSource, MonitorDpiType dpiType = MonitorDpiType.Default)
        {
            if (!IsSupported)
            {
                return(Dpi.Default);
            }

            var  hMonitor = DpiMethods.MonitorFromWindow(hwndSource.Handle, DpiMethods.MonitorDefaultTo.Nearest);
            uint dpiX = 1, dpiY = 1;

            DpiMethods.GetDpiForMonitor(hMonitor, dpiType, ref dpiX, ref dpiY);

            return(new Dpi(dpiX, dpiY));
        }
Esempio n. 4
0
 /// <summary>
 /// DPIスケールを取得する
 /// </summary>
 /// <param name="hwnd">ウィンドウハンドル</param>
 /// <returns>スケール</returns>
 public static float   GetDisplayScaleFactor(IntPtr hwnd)
 {
     return((float)GetDpiForMonitor(DpiMethods.MonitorFromWindow(hwnd, DpiMethods.MonitorDefaultTo.Nearest)).DpiScaleX);
 }
Esempio n. 5
0
        /// <summary>
        /// 指定スクリーンにおけるDPI情報を取得する
        /// </summary>
        /// <param name="screen">スクリーン</param>
        /// <returns>DpiScale</returns>
        public static DpiScale        GetDpi(System.Windows.Forms.Screen screen)
        {
            var point = new System.Drawing.Point(screen.Bounds.Left + 1, screen.Bounds.Top + 1);

            return(GetDpiForMonitor(DpiMethods.MonitorFromPoint(point, DpiMethods.MonitorDefaultTo.Nearest)));
        }