Full solution here (based on all answers). I added the MinPercentOnScreen parameter, where at least this% of the pixels should be visible on all screens / displays. Therefore, if this returns false , you will need to move the default position of the window.
// Return True if a certain percent of a rectangle is shown across the total screen area of all monitors, otherwise return False. public bool IsOnScreen(System.Drawing.Point RecLocation, System.Drawing.Size RecSize, double MinPercentOnScreen = 0.2) { double PixelsVisible = 0; System.Drawing.Rectangle Rec = new System.Drawing.Rectangle(RecLocation, RecSize); foreach (Screen Scrn in Screen.AllScreens) { System.Drawing.Rectangle r = System.Drawing.Rectangle.Intersect(Rec, Scrn.WorkingArea); // intersect rectangle with screen if (r.Width != 0 & r.Height != 0) { PixelsVisible += (r.Width * r.Height); // tally visible pixels } } return PixelsVisible >= (Rec.Width * Rec.Height) * MinPercentOnScreen; }
Implementation:
return IsOnScreen(this.Location, this.Size);
CrazyTim Apr 13 '15 at 12:52 2015-04-13 00:52
source share