完全解答(すべての回答に基づく)。私はすべての画面/ディスプレイで少なくともこの%のピクセルを表示する必要があるパラメータMinPercentOnScreen
を追加しました。したがって、これがfalse
を返す場合は、ウィンドウの位置をデフォルトに戻す必要があります。
// 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;
}
実装:
return IsOnScreen(this.Location, this.Size);
私は、私は、フォームの画面解像度、サイズと位置を取得することにより、いくつかのトリッキーなロジックを実行することができます承知していることを言及する必要がありますが、私は少し何かを期待していましたよりエレガント。 – Cody
あなたは本当にそのフォームを配置するよりエレガントだと思って、解像度/サイズの外にあるかどうかを確認して、それを再配置しますか?より洗練されたソリューションは、あなたが行う前にあなたがスクリーンから離れているかどうかを確認することです。 –