Recently, I had a customer report that the application I am writing got stuck off screen, and he couldn’t get at it. This happened by moving the application to his external monitor and then minimizing. After disconnecting the monitor, he would restore the application and it would be positioned off screen (on the now disconnected monitor).
To solve this problem, I just look at all available screens and make sure that the location of the window is inside the working area of one of them. If it is not, I move it to the primary display:
bool visible = false;
foreach (var screen in Screen.AllScreens)
{
if (screen.WorkingArea.Contains(this.DesktopLocation))
{
visible = true;
break;
}
}
if (!visible)
this.Location = new Point(100, 100);
