Xamarin-2938: Fix Screen.FromControl
authorEberhard Beilharz <eb1@sil.org>
Tue, 17 Jan 2012 16:18:35 +0000 (17:18 +0100)
committerMiguel de Icaza <miguel@gnome.org>
Fri, 20 Jan 2012 03:01:53 +0000 (22:01 -0500)
We have to convert the location of the control to screen coordinates
so that we end up with the correct screen in a multi-monitor setup.
This patch fixes Screen.FromControl, Screen.FromHandle, and
Screen.GetWorkingArea.

Change-Id: I6c4fd65833d012e832d97d610c79abc792e57adf

mcs/class/Managed.Windows.Forms/System.Windows.Forms/Screen.cs

index e8a1c56e1a3f9af9e0e3ecd01ee8a9666cf79902..eeb4f80000b96c0abe129155c934f43dc56f92b7 100644 (file)
@@ -108,7 +108,8 @@ namespace System.Windows.Forms {
 
                #region Public Static Methods
                public static Screen FromControl(Control control) {
-                       return Screen.FromPoint(control.Location);
+                       var point = control.Parent != null ? control.Parent.PointToScreen(control.Location) : control.Location;
+                       return Screen.FromPoint(point);
                }
 
                public static Screen FromHandle(IntPtr hwnd) {
@@ -116,7 +117,8 @@ namespace System.Windows.Forms {
 
                        control = Control.FromHandle(hwnd);
                        if (control != null) {
-                               return Screen.FromPoint(control.Location);
+                               var point = control.Parent != null ? control.Parent.PointToScreen(control.Location) : control.Location;
+                               return Screen.FromPoint(point);
                        }
                        return Screen.PrimaryScreen;
                }