SIL.FieldWorks.Common.Framework.FwApp.AdjustNewWindowPosition C# (CSharp) Method

AdjustNewWindowPosition() protected method

Adjust the new window position - offset right and down from the original. Also copy the window size, state, and set the StartPosition mode to manual.
protected AdjustNewWindowPosition ( Form wndNew, Form wndCopyFrom ) : void
wndNew System.Windows.Forms.Form
wndCopyFrom System.Windows.Forms.Form
return void
		protected void AdjustNewWindowPosition(Form wndNew, Form wndCopyFrom)
		{
			Debug.Assert(wndNew is IFwMainWnd,
				"Form passed as parameter to AdjustNewWindowPosition has to implement IFwMainWnd");
			Debug.Assert(wndCopyFrom is IFwMainWnd,
				"Form passed as parameter to AdjustNewWindowPosition has to implement IFwMainWnd");

			// Get position and size
			Rectangle rcNewWnd = wndCopyFrom.DesktopBounds;

			// However, desktopBounds are not useful when window is maximized; in that case
			// get the info from Persistence instead... NormalStateDesktopBounds
			if (wndCopyFrom.WindowState == FormWindowState.Maximized)
			{
				// Here we subtract twice the caption height, which with the offset below insets it all around.
				rcNewWnd.Width -=  SystemInformation.CaptionHeight * 2;
				rcNewWnd.Height -=  SystemInformation.CaptionHeight * 2;
				// JohnT: this old approach fails if the old window's position has never been
				// persisted. NormalStateDesktopBounds crashes, not finding anything in the
				// property table.
				//				rcNewWnd = ((IFwMainWnd)wndCopyFrom).NormalStateDesktopBounds;
			}

			//Offset right and down
			rcNewWnd.X += SystemInformation.CaptionHeight;
			rcNewWnd.Y += SystemInformation.CaptionHeight;

			// We we will check if we went too far right or down, as Word 2002 checks.
			// If rcNewWnd is beyond bottom or right of screen...
			// Get the working area of the screen on which the new window will be placed.
			//Rectangle rcScrn = Screen.FromRectangle(rcNewWnd).WorkingArea;

			// If our adjusted rcNewWnd is partly off the screen, move it so it is fully
			// on the screen its mostly on. Note: this will only be necessary when the window
			// being copied from is partly off the screen in a single monitor system or
			// spanning multiple monitors in a multiple monitor system.
			ScreenUtils.EnsureVisibleRect(ref rcNewWnd);

			// Set the properties of the new window
			wndNew.DesktopBounds = rcNewWnd;
			wndNew.StartPosition = FormStartPosition.Manual;
			wndNew.WindowState = wndCopyFrom.WindowState;
		}