private void RestoreMdiContainerState(MdiContainerWithState mdiContainerWithState) { MdiContainerForm mdiContainerForm = mdiContainerWithState.Form; PersistableFormState formState = mdiContainerWithState.State.FormState; bool boundsInitialized = false; Rectangle targetBounds = formState.Bounds; // If all bounds are known initialize from those. // Do make sure the window ends up on a visible working area. targetBounds.Intersect(Screen.GetWorkingArea(targetBounds)); if (targetBounds.Width >= mdiContainerForm.MinimumSize.Width && targetBounds.Height >= mdiContainerForm.MinimumSize.Height) { mdiContainerForm.SetBounds(targetBounds.Left, targetBounds.Top, targetBounds.Width, targetBounds.Height, BoundsSpecified.All); boundsInitialized = true; } // Determine a window state independently if no formState was applied successfully. if (!boundsInitialized) { SetDefaultSizeAndPosition(mdiContainerForm); } // Restore maximized setting after setting the Bounds. if (formState.Maximized) { mdiContainerForm.WindowState = FormWindowState.Maximized; } }
private void AttachFormStateAutoSaver(MdiContainerWithState mdiContainerWithState) { PersistableFormState formState = mdiContainerWithState.State.FormState; formState.AttachTo(mdiContainerWithState.Form); formState.Changed += (_, __) => AutoSaveMdiContainerList(); }
public MdiContainerState(PersistableFormState formState) { FormState = formState; }