public override void RunLayout(MDIContainer container) { if (container == null) { return; } if (!container.Items.Children.Any()) { return; } var items = container.Items.Children; MDIChild lastItem = null; for (var i = 0; i < items.Count; i++) { var item = (MDIChild)items[i]; Canvas.SetLeft(item, i * 30); Canvas.SetTop(item, i * 30); if (Resize && item.FormBorderStyle != FormBorderStyle.Fixed) { item.Width = container.DefaultChildWidth; item.Height = container.DefaultChildHeight; } lastItem = item; } lastItem?.Activate(); }
private void CreateChildEventHandlers(MDIChild child) { child.Restored += ChildOnRestored; child.Closed += ChildOnClosed; child.Activating += ChildOnActivating; child.MinimizeButton.Click += OnMinimizeButtonOnClick; child.Activated += OnChildOnActivated; }
private void RemoveChildEventHandlers(MDIChild child) { child.Loaded -= ChildOnLoaded; child.Restored -= ChildOnRestored; child.Activating -= ChildOnActivating; child.MinimizeButton.Click -= OnMinimizeButtonOnClick; child.Activated -= OnChildOnActivated; child.Closed -= ChildOnClosed; }
private void ChildOnRestored(object o, MDIChild child) { if (child.PreviousFormWindowState != FormWindowState.Minimized) { return; } MinimizedItems.Items?.Remove(child); Items.Children.Add(child); }
private void ChildOnActivating(object mdiChild, MDIChild mdiChildControl) { foreach (var item in Items.Children.Where(x => x != mdiChild)) { if (item is MDIChild control) { control.Deactivate(); } } }
private MDIChild CreateMdiControl(Control control) { var child = new MDIChild(control) { Width = double.IsNaN(control.Width) ? DefaultChildWidth : control.Width, Height = double.IsNaN(control.Height) ? DefaultChildHeight : control.Height }; return(child); }
private void ChildOnClosed(object sender, MDIChild child) { if (child.FormWindowState == FormWindowState.Minimized) { MinimizedItems.Items?.Remove(child); } else { Items.Children.Remove(child); } RemoveChildEventHandlers(child); }
private static void HandleStartPosition(Control control, MDIChild child, MDIContainer mdiContainer) { double startLeft; double startTop; var startPosition = FormStartPosition.WindowsDefaultLocation; var apStart = control.GetValue(FormProperties.FormStartPositionProperty); if (apStart != null) { startPosition = (FormStartPosition)apStart; } if (startPosition == FormStartPosition.CenterParent) { var screenWidth = mdiContainer.ActualWidth; var screenHeight = mdiContainer.ActualHeight; var windowWidth = child.Width; var windowHeight = child.Height; startLeft = screenWidth / 2 - windowWidth / 2; startTop = screenHeight / 2 - windowHeight / 2; } else if (startPosition == FormStartPosition.CenterScreen) { var displaySize = Helpers.GetCurrentDisplaySize(); var screenWidth = displaySize.Width; var screenHeight = displaySize.Height; var windowWidth = child.Width; var windowHeight = child.Height; startLeft = screenWidth / 2 - windowWidth / 2; startTop = screenHeight / 2 - windowHeight / 2; } else { var screenWidth = mdiContainer.ActualWidth; var screenHeight = mdiContainer.ActualHeight; var windowWidth = child.Width; var windowHeight = child.Height; var maxLeft = screenWidth / 2 - windowWidth / 2; var maxTop = screenHeight / 2 - windowHeight / 2; var rnd = new Random(); startLeft = rnd.Next(0, (int)maxLeft); startTop = rnd.Next(0, (int)maxTop); } Canvas.SetLeft(child, startLeft); Canvas.SetTop(child, startTop); }
private void OnChildOnActivated(object sender, MDIChild mdiChild) { }
private static void ConfigureMdiControl(Control control, MDIChild child, MDIContainer mdiContainer) { HandleStartPosition(control, child, mdiContainer); }