public void CascadeWindows(Form wndCurr)
{
CheckDisposed();
// Get the screen in which to cascade.
Screen scrn = Screen.FromControl(wndCurr);
Rectangle rcScrnAdjusted = ScreenUtils.AdjustedWorkingArea(scrn);
Rectangle rcUpperLeft = rcScrnAdjusted;
rcUpperLeft.Width = CascadeSize(rcUpperLeft.Width, wndCurr.MinimumSize.Width);
rcUpperLeft.Height = CascadeSize(rcUpperLeft.Height, wndCurr.MinimumSize.Height);
Rectangle rc = rcUpperLeft;
foreach (Form wnd in MainWindows)
{
// Ignore windows that are on other screens or which are minimized.
if (scrn.WorkingArea == Screen.FromControl(wnd).WorkingArea &&
wnd != wndCurr &&
wnd.WindowState != FormWindowState.Minimized)
{
if (wnd.WindowState == FormWindowState.Maximized)
wnd.WindowState = FormWindowState.Normal;
wnd.DesktopBounds = rc;
wnd.Activate();
rc.Offset(SystemInformation.CaptionHeight, SystemInformation.CaptionHeight);
if (!rcScrnAdjusted.Contains(rc))
{
rc = rcUpperLeft;
}
}
}
// Make the active window the last one and activate it.
if (wndCurr.WindowState == FormWindowState.Maximized)
wndCurr.WindowState = FormWindowState.Normal;
wndCurr.DesktopBounds = rc;
wndCurr.Activate();
}