Example #1
0
		public static Rect Validate(Rect bounds)
		{
			// Check if form is outside the screen and get it back if necessary.
			// This is important when the user uses multiple screens, a window stores its location
			// on the secondary monitor and then the secondary monitor is removed.
			foreach (var screen in Screen.AllScreens) {
				var rect = System.Drawing.Rectangle.Intersect(bounds.ToSystemDrawing(), screen.WorkingArea);
				if (rect.Width > 10 && rect.Height > 10)
					return bounds;
			}
			// center on primary screen
			// TODO : maybe use screen where main window is most visible?
			var targetScreen = Screen.PrimaryScreen;
			return new Rect((targetScreen.WorkingArea.Width - bounds.Width) / 2, (targetScreen.WorkingArea.Height - bounds.Height) / 2, bounds.Width, bounds.Height);
		}