[MWF] Implement multi-display support on Linux (Fixes #325669)
[mono.git] / mcs / class / Managed.Windows.Forms / System.Windows.Forms / Form.cs
index 897bc75ea6b84ad6c6449e982e6a9df0238434d1..5b6ed663ee251300d8c4ac1396f8796004961a30 100644 (file)
@@ -1872,9 +1872,8 @@ namespace System.Windows.Forms {
                }
 
                protected void CenterToScreen() {
-                       Size    DisplaySize;
-                       int     w;
-                       int     h;
+                       int w;
+                       int h;
 
                        // MS creates the handle here.
                        if (TopLevel) {
@@ -1894,8 +1893,14 @@ namespace System.Windows.Forms {
                                h = DefaultSize.Height;
                        }
 
-                       XplatUI.GetDisplaySize(out DisplaySize);
-                       this.Location = new Point(DisplaySize.Width / 2 - w / 2, DisplaySize.Height / 2 - h / 2);
+                       Rectangle workingArea;
+                       if (Owner == null) {
+                               workingArea = Screen.FromPoint (MousePosition).WorkingArea;
+                       } else {
+                               workingArea = Screen.FromControl (Owner).WorkingArea;
+                       }
+                       this.Location = new Point (workingArea.Left + workingArea.Width / 2 - w / 2,
+                               workingArea.Top + workingArea.Height / 2 - h / 2);
                }
 
                [EditorBrowsable(EditorBrowsableState.Advanced)]