Advertisement
yumetodo

WPF_IsLocationGood

Sep 29th, 2017
205
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.06 KB | None | 0 0
  1.         private bool IsLocationGood()
  2.         {
  3.             //abort
  4.             if (0 == this.dpiOld) return false;
  5.             var factor = dpiNew / dpiOld;
  6.             var widthDiff = Convert.ToInt32(SystemParameters.WorkArea.Width * factor) - SystemParameters.WorkArea.Width;
  7.             var heightDiff = Convert.ToInt32(SystemParameters.WorkArea.Height * factor) - SystemParameters.WorkArea.Height;
  8.             var r = new Rect(this.RenderSize);
  9.             var rect = new RECT() { left = (int)r.Left, top = (int)r.Top, right = (int)r.Right, bottom = (int)r.Bottom };
  10.             //Get handle to monitor that has the largest intersection with the rectangle.
  11.             var handleMonitor = W32.MonitorFromRect(ref rect, W32.MONITOR_DEFAULTTONULL);
  12.             if (IntPtr.Zero == handleMonitor) return false;
  13.             uint dpiX = 0;
  14.             uint dpiY = 0;
  15.             var result = W32.GetDpiForMonitor(handleMonitor, MonitorDpiType.Default, ref dpiX, ref dpiY);
  16.             if (IntPtr.Zero != result) return false;
  17.             return (dpiX == dpiNew);
  18.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement