diff --git a/src/Eto.Wpf/WpfHelpers.cs b/src/Eto.Wpf/WpfHelpers.cs
index 9d3c39842..9f94dc8fa 100755
--- a/src/Eto.Wpf/WpfHelpers.cs
+++ b/src/Eto.Wpf/WpfHelpers.cs
@@ -85,25 +85,44 @@ public static Window ToEtoWindow(IntPtr windowHandle)
}
///
- /// Converts a System.Drawing.Point in screen coordinates to an Eto point in screen coordinates.
+ /// Converts a point in native (Windows Forms/Win32) screen coordinates to a point in Eto logical screen coordinates.
///
/// A point in Windows Forms/win32 screen coordinates.
+ /// The screen to translate to, if known.
+ /// True to get screen bounds/location in per monitor mode, false to remain in current mode.
/// A point in Eto screen coordinates.
- public static PointF ToEtoScreen(this sd.Point point, swf.Screen sdscreen = null, bool perMonitor = false) => Win32.ScreenToLogical(point, sdscreen, perMonitor);
+ public static PointF ToEtoScreen(this Point point, Screen screen = null, bool perMonitor = false) => Win32.ScreenToLogical(point, ScreenHandler.GetControl(screen), perMonitor);
- public static RectangleF ToEtoScreen(this sd.Rectangle rect, swf.Screen sdscreen = null, bool perMonitor = false)
+ ///
+ /// Converts a rectangle in native (Windows Forms/Win32) screen coordinates to an rectangle in Eto logical screen coordinates.
+ ///
+ /// A rectangle in Windows Forms/win32 screen coordinates.
+ /// The screen to translate to, if known.
+ /// True to get screen bounds/location in per monitor mode, false to remain in current mode.
+ /// A point in Eto screen coordinates.
+ public static RectangleF ToEtoScreen(this Rectangle rect, Screen screen = null, bool perMonitor = false)
{
- var topLeft = ToEtoScreen(rect.Location, sdscreen, perMonitor);
- var bottomRight = ToEtoScreen(new sd.Point(rect.X + rect.Width, rect.Y + rect.Height), sdscreen, perMonitor);
+ var topLeft = ToEtoScreen(rect.Location, screen, perMonitor);
+ var bottomRight = ToEtoScreen(new Point(rect.X + rect.Width, rect.Y + rect.Height), screen, perMonitor);
return new RectangleF(topLeft, new SizeF(bottomRight.X - topLeft.X, bottomRight.Y - topLeft.Y));
}
///
- /// Converts a point in Eto screen coordinates to a point in Windows Forms/win32 screen coordinates.
+ /// Converts a point in Eto logical screen coordinates to a point in native (Windows Forms/win32) screen coordinates.
///
/// A point in Eto screen coordinates.
+ /// The screen to translate to, if known.
+ /// True to get screen bounds/location in per monitor mode, false to remain in current mode.
/// A point in Windows Forms/win32 screen coordinates.
public static Point ToNativeScreen(this PointF point, Screen screen = null, bool perMonitor = false) => Win32.LogicalToScreen(point, screen, perMonitor);
+
+ ///
+ /// Converts a rectangle in Eto logical screen coordinates to a rectangle in native (Windows Forms/win32) screen coordinates.
+ ///
+ /// A rectangle in Eto screen coordinates.
+ /// The screen to translate to, if known.
+ /// True to get screen bounds/location in per monitor mode, false to remain in current mode.
+ /// A rectangle in Windows Forms/win32 screen coordinates.
public static Rectangle ToNativeScreen(this RectangleF rect, Screen screen = null, bool perMonitor = false)
{
var topLeft = rect.TopLeft.ToNativeScreen(screen, perMonitor);
diff --git a/test/Eto.Test.Wpf/UnitTests/ScreenToClientTests.cs b/test/Eto.Test.Wpf/UnitTests/ScreenToClientTests.cs
index d191edf77..5c1e93d4f 100755
--- a/test/Eto.Test.Wpf/UnitTests/ScreenToClientTests.cs
+++ b/test/Eto.Test.Wpf/UnitTests/ScreenToClientTests.cs
@@ -6,6 +6,7 @@
using NUnit.Framework;
using swf = System.Windows.Forms;
using sd = System.Drawing;
+using Eto.Wpf.Forms;
namespace Eto.Test.Wpf.UnitTests
{
@@ -53,7 +54,7 @@ void CreateWindow(Rectangle rect)
window.Show();
windows.Add(window);
- bool perMonitor = true;
+ bool perMonitor = false;
var sdrect = WpfHelpers.ToNativeScreen(rect, window.Screen, perMonitor: perMonitor).ToSD();
@@ -70,12 +71,12 @@ void CreateWindow(Rectangle rect)
wfwindow.LocationChanged += (sender, e) =>
{
var loc = wfwindow.RectangleToScreen(wfwindow.ClientRectangle);
- window.Bounds = (Rectangle)WpfHelpers.ToEtoScreen(loc, swf.Screen.FromControl(wfwindow), perMonitor: perMonitor);
+ window.Bounds = (Rectangle)WpfHelpers.ToEtoScreen(loc.ToEto(), window.Screen, perMonitor: perMonitor);
};
wfwindow.SizeChanged += (sender, e) =>
{
var loc = wfwindow.RectangleToScreen(wfwindow.ClientRectangle);
- window.Bounds = (Rectangle)WpfHelpers.ToEtoScreen(loc, swf.Screen.FromControl(wfwindow), perMonitor: perMonitor);
+ window.Bounds = (Rectangle)WpfHelpers.ToEtoScreen(loc.ToEto(), window.Screen, perMonitor: perMonitor);
};
wfwindow.Show();
wfwindows.Add(wfwindow);