/// ------------------------------------------------------------------------------------ /// <summary> /// Arrange the windows top to bottom or left to right. /// </summary> /// <param name="wndCurr">Current Window (i.e. window whose menu was used to issue a /// tile vertical or horizontal command.</param> /// <param name="windowsToTile">A list of all the windows to tile (including the /// current window)</param> /// <param name="orientation">The value indicating whether to tile side by side or /// stacked.</param> /// ------------------------------------------------------------------------------------ public void TileWindows(Form wndCurr, List<IFwMainWnd> windowsToTile, WindowTiling orientation) { CheckDisposed(); // Get the screen in which to tile. Screen scrn = Screen.FromControl(wndCurr); int desiredDimension, windowSpacing; // At this point, assume the entire screen's working area is the desired size // and location for tiled windows, even though it's highly likely this will // change below. Rectangle rcDesired = scrn.WorkingArea; // Get the proper window width or height and the space between the windows // as they are tiled. if (orientation == WindowTiling.Stacked) { CalcTileSizeAndSpacing(scrn, windowsToTile, scrn.WorkingArea.Height, wndCurr.MinimumSize.Height, out desiredDimension, out windowSpacing); rcDesired.Height = desiredDimension; } else { CalcTileSizeAndSpacing(scrn, windowsToTile, scrn.WorkingArea.Width, wndCurr.MinimumSize.Width, out desiredDimension, out windowSpacing); rcDesired.Width = desiredDimension; } // There is a strange situation when a user's task bar is at the right or top // of the primary display. The working area returns the correct rectangle that // does not include the task bar. However, we cannot set a widnow's X or Y // coordinate to the working area's X or Y. If the window is to be located // in the upper left corner next to the task bar, X and Y must be 0. rcDesired.X -= ScreenUtils.TaskbarWidth; rcDesired.Y -= ScreenUtils.TaskbarHeight; // Move the active window to its proper place and size. wndCurr.DesktopBounds = rcDesired; // Now move the rest of the non minimized windows to their proper place. foreach (Form wnd in windowsToTile) { if (wnd.WindowState == FormWindowState.Maximized) wnd.WindowState = FormWindowState.Normal; if (wnd != wndCurr && wnd.WindowState != FormWindowState.Minimized && Screen.FromControl(wnd).WorkingArea == scrn.WorkingArea) { if (orientation == WindowTiling.Stacked) rcDesired.Y += windowSpacing; else rcDesired.X += windowSpacing; wnd.DesktopBounds = rcDesired; } } // If there was any overlapping of tiled windows, go from bottom to the top // or right to left and activate each window so the tiling looks correct. i.e. // Each window is overlapped on its top edge by the window directly on top or left. if (windowSpacing != desiredDimension) { for (int i = windowsToTile.Count - 1; i >= 0; i--) { if (windowsToTile[i] != wndCurr && ((Form)windowsToTile[i]).WindowState != FormWindowState.Minimized && Screen.FromControl((Form)windowsToTile[i]).WorkingArea == scrn.WorkingArea) { ((Form)windowsToTile[i]).Activate(); } } } // Finally, make the current window active. wndCurr.Activate(); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Arrange the windows top to bottom or left to right. /// </summary> /// <param name="wndCurr">Current Window (i.e. window whose menu was used to issue a /// tile vertical or horizontal command.</param> /// <param name="orientation">The value indicating whether to tile side by side or /// stacked.</param> /// ------------------------------------------------------------------------------------ public void TileWindows(Form wndCurr, WindowTiling orientation) { CheckDisposed(); TileWindows(wndCurr, MainWindows, orientation); }