Created
August 8, 2012 04:25
-
-
Save ngyuki/3292015 to your computer and use it in GitHub Desktop.
フォームなどの Rectangle が画面内に収まるようにサイズや表示位置を調整する(マルチモニタ対応)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private Rectangle AdjustmentWindowBounds(Rectangle bounds) | |
{ | |
var workarea = Screen.FromRectangle(bounds).WorkingArea; | |
if (workarea.Contains(bounds) == false) | |
{ | |
if (bounds.Width > workarea.Width) | |
{ | |
bounds.Width = workarea.Width; | |
} | |
if (bounds.Height > workarea.Height) | |
{ | |
bounds.Height = workarea.Height; | |
} | |
if (bounds.Right > workarea.Right) | |
{ | |
bounds.Offset(workarea.Right - bounds.Right, 0); | |
} | |
if (bounds.Bottom > workarea.Bottom) | |
{ | |
bounds.Offset(0, workarea.Bottom - bounds.Bottom); | |
} | |
if (bounds.Left < workarea.Left) | |
{ | |
bounds.Offset(workarea.Left - bounds.Left, 0); | |
} | |
if (bounds.Top < workarea.Top) | |
{ | |
bounds.Offset(0, workarea.Top - bounds.Top); | |
} | |
} | |
return bounds; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment