private void MainForm_Load(object sender, EventArgs e)
{
Rectangle newBounds = new Rectangle {
X = settings.GetValue("mainForm.Location.X", Location.X),
Y = settings.GetValue("mainForm.Location.Y", Location.Y),
Width = settings.GetValue("mainForm.Width", 470),
Height = settings.GetValue("mainForm.Height", 640)
};
Rectangle fullWorkingArea = new Rectangle(int.MaxValue, int.MaxValue,
int.MinValue, int.MinValue);
foreach (Screen screen in Screen.AllScreens)
fullWorkingArea = Rectangle.Union(fullWorkingArea, screen.Bounds);
Rectangle intersection = Rectangle.Intersect(fullWorkingArea, newBounds);
if (intersection.Width < 20 || intersection.Height < 20 ||
!settings.Contains("mainForm.Location.X")
) {
newBounds.X = (Screen.PrimaryScreen.WorkingArea.Width / 2) -
(newBounds.Width/2);
newBounds.Y = (Screen.PrimaryScreen.WorkingArea.Height / 2) -
(newBounds.Height / 2);
}
this.Bounds = newBounds;
}