View | Details | Raw Unified | Return to bug 8271
Collapse All | Expand All

(-)a/mcs/class/Managed.Windows.Forms/System.Windows.Forms/Screen.cs (-1 / +27 lines)
Lines 147-153 namespace System.Windows.Forms { Link Here
147
		}
147
		}
148
148
149
		public static Screen FromRectangle(Rectangle rect) {
149
		public static Screen FromRectangle(Rectangle rect) {
150
			return Screen.FromPoint(new Point(rect.Left, rect.Top));
150
			Screen bestScrn = null;
151
			int closest = 0;
152
			foreach (Screen scrn in Screen.AllScreens) {
153
				Rectangle rcBounds = scrn.Bounds;
154
				int distance = 0;
155
				if (rect.Left > rcBounds.Right)
156
					distance += rect.Left - rcBounds.Right;
157
				else if (rcBounds.Left > rect.Left)
158
					distance += rcBounds.Left - rect.Left;
159
				if (rcBounds.Left > rect.Right)
160
					distance += rcBounds.Left - rect.Right;
161
				else if (rect.Right > rcBounds.Right)
162
					distance += rect.Right - rcBounds.Right;
163
				if (rect.Top > rcBounds.Bottom)
164
					distance += rect.Top - rcBounds.Bottom;
165
				else if (rcBounds.Top > rect.Top)
166
					distance += rcBounds.Top - rect.Top;
167
				if (rcBounds.Top > rect.Bottom)
168
					distance += rcBounds.Top - rect.Bottom;
169
				else if (rect.Bottom > rcBounds.Bottom)
170
					distance += rect.Bottom - rcBounds.Bottom;
171
				if (bestScrn == null || distance < closest) {
172
					bestScrn = scrn;
173
					closest = distance;
174
				}
175
			}
176
			return bestScrn;
151
		}
177
		}
152
178
153
		public static Rectangle GetBounds(Control ctl) {
179
		public static Rectangle GetBounds(Control ctl) {

Return to bug 8271