Eto.Forms.Screen.FromRectangle C# (CSharp) Method

FromRectangle() public static method

Gets the screen that encompases the biggest part of the specified rectangle, or the closest screen to the rectangle if it is outside the bounds of all screens..
public static FromRectangle ( Eto.Drawing.RectangleF rectangle ) : Screen
rectangle Eto.Drawing.RectangleF Rectangle to find the screen.
return Screen
		public static Screen FromRectangle(RectangleF rectangle)
		{
			Screen foundScreen = null;
			float foundArea = 0;
			var screens = Screens.ToArray();
			foreach (var screen in screens)
			{
				var rect = rectangle;
				rect.Intersect(screen.Bounds);
				var area = rect.Size.Width * rect.Size.Height;
				if (area > foundArea)
				{
					foundScreen = screen;
					foundArea = area;
				}
			}
			if (foundScreen != null)
				return foundScreen;

			// find by distance
			float foundDistance = float.MaxValue;
			foreach (var screen in screens)
			{
				var diff = RectangleF.Distance(rectangle, screen.Bounds);
				var distance = (float)Math.Sqrt(diff.Width * diff.Width + diff.Height * diff.Height);
				if (distance < foundDistance)
				{
					foundScreen = screen;
					foundDistance = distance;
				}
			}
			return foundScreen ?? PrimaryScreen;
		}
	}