Skip to content

Commit

Permalink
Fix reporting the location of a Hwnd form with multi-monitor DPIs
Browse files Browse the repository at this point in the history
  • Loading branch information
cwensley committed Jan 26, 2024
1 parent 443b56c commit 3bb3534
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions src/Eto.WinForms/Forms/HwndFormHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,25 +81,26 @@ public float LogicalPixelSize
{
if (Win32.PerMonitorDpiSupported)
return Win32.GetWindowDpi(Control) / 96.0f;
var screen = swf.Screen.FromHandle(Control);
if (screen == null)
return 1;
return screen.GetLogicalPixelSize();
return SwfScreen?.GetLogicalPixelSize() ?? 1;
}
}

swf.Screen SwfScreen => swf.Screen.FromHandle(Control);

public Eto.Drawing.Point Location
{
get
{
Win32.RECT rect;
Win32.GetWindowRect(Control, out rect);
var location = new PointF(rect.left, rect.top);
return Point.Round(location / (float)LogicalPixelSize);
var rect = new Win32.RECT();
Win32.ExecuteInDpiAwarenessContext(() => Win32.GetWindowRect(Control, out rect));

var location = new Point(rect.left, rect.top);
return Point.Round(location.ScreenToLogical(SwfScreen));
}
set
{
throw new NotImplementedException();
var loc = ((PointF)value).LogicalToScreen();
Win32.ExecuteInDpiAwarenessContext(() => Win32.SetWindowPos(Control, IntPtr.Zero, loc.X, loc.Y, 0, 0, Win32.SWP.NOSIZE | Win32.SWP.NOACTIVATE));
}
}

Expand Down

0 comments on commit 3bb3534

Please sign in to comment.