Beispiel #1
0
        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();
        }
Beispiel #2
0
 private void CreateChildEventHandlers(MDIChild child)
 {
     child.Restored             += ChildOnRestored;
     child.Closed               += ChildOnClosed;
     child.Activating           += ChildOnActivating;
     child.MinimizeButton.Click += OnMinimizeButtonOnClick;
     child.Activated            += OnChildOnActivated;
 }
Beispiel #3
0
 private void RemoveChildEventHandlers(MDIChild child)
 {
     child.Loaded               -= ChildOnLoaded;
     child.Restored             -= ChildOnRestored;
     child.Activating           -= ChildOnActivating;
     child.MinimizeButton.Click -= OnMinimizeButtonOnClick;
     child.Activated            -= OnChildOnActivated;
     child.Closed               -= ChildOnClosed;
 }
Beispiel #4
0
        private void ChildOnRestored(object o, MDIChild child)
        {
            if (child.PreviousFormWindowState != FormWindowState.Minimized)
            {
                return;
            }

            MinimizedItems.Items?.Remove(child);
            Items.Children.Add(child);
        }
Beispiel #5
0
 private void ChildOnActivating(object mdiChild, MDIChild mdiChildControl)
 {
     foreach (var item in Items.Children.Where(x => x != mdiChild))
     {
         if (item is MDIChild control)
         {
             control.Deactivate();
         }
     }
 }
Beispiel #6
0
        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);
        }
Beispiel #7
0
        private void ChildOnClosed(object sender, MDIChild child)
        {
            if (child.FormWindowState == FormWindowState.Minimized)
            {
                MinimizedItems.Items?.Remove(child);
            }
            else
            {
                Items.Children.Remove(child);
            }

            RemoveChildEventHandlers(child);
        }
Beispiel #8
0
        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);
        }
Beispiel #9
0
 private void OnChildOnActivated(object sender, MDIChild mdiChild)
 {
 }
Beispiel #10
0
 private static void ConfigureMdiControl(Control control, MDIChild child, MDIContainer mdiContainer)
 {
     HandleStartPosition(control, child, mdiContainer);
 }