Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix reporting the location of a Hwnd form with multi-monitor DPIs #2610

Merged
merged 1 commit into from
Jan 26, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading