void LayoutDockedChildren(Control parent, Control[] controls) { Rectangle space = parent.DisplayRectangle; MdiClient mdi = null; // Deal with docking; go through in reverse, MS docs say that lowest Z-order is closest to edge for (int i = controls.Length - 1; i >= 0; i--) { Control child = controls[i]; Size child_size = child.Size; #if NET_2_0 if (child.AutoSize) { child_size = GetPreferredControlSize(child); } #endif if (!child.VisibleInternal || child.ControlLayoutType == Control.LayoutType.Anchor) { continue; } // MdiClient never fills the whole area like other controls, have to do it later if (child is MdiClient) { mdi = (MdiClient)child; continue; } switch (child.Dock) { case DockStyle.None: // Do nothing break; case DockStyle.Left: child.SetBoundsInternal(space.Left, space.Y, child_size.Width, space.Height, BoundsSpecified.None); space.X += child.Width; space.Width -= child.Width; break; case DockStyle.Top: child.SetBoundsInternal(space.Left, space.Y, space.Width, child_size.Height, BoundsSpecified.None); space.Y += child.Height; space.Height -= child.Height; break; case DockStyle.Right: child.SetBoundsInternal(space.Right - child_size.Width, space.Y, child_size.Width, space.Height, BoundsSpecified.None); space.Width -= child.Width; break; case DockStyle.Bottom: child.SetBoundsInternal(space.Left, space.Bottom - child_size.Height, space.Width, child_size.Height, BoundsSpecified.None); space.Height -= child.Height; break; case DockStyle.Fill: child.SetBoundsInternal(space.Left, space.Top, space.Width, space.Height, BoundsSpecified.None); break; } } // MdiClient gets whatever space is left if (mdi != null) { mdi.SetBoundsInternal(space.Left, space.Top, space.Width, space.Height, BoundsSpecified.None); } }
static void LayoutDockedChildren(Control parent, IList controls) { Rectangle space = parent.DisplayRectangle; MdiClient mdi = null; // Deal with docking; go through in reverse, MS docs say that lowest Z-order is closest to edge for (int i = controls.Count - 1; i >= 0; i--) { Control child = (Control)controls[i]; if (!child.VisibleInternal || child.Dock == DockStyle.None) { continue; } Size child_size = child.Size; // MdiClient never fills the whole area like other controls, have to do it later if (child is MdiClient) { mdi = (MdiClient)child; continue; } switch (child.Dock) { case DockStyle.None: // Do nothing break; case DockStyle.Left: if (child.AutoSizeInternal) { child_size = child.GetPreferredSize(new Size(0, space.Height)); } child.SetBoundsInternal(space.Left, space.Y, child_size.Width, space.Height, BoundsSpecified.None); space.X += child.Width; space.Width -= child.Width; break; case DockStyle.Top: if (child.AutoSizeInternal) { child_size = child.GetPreferredSize(new Size(space.Width, 0)); } child.SetBoundsInternal(space.Left, space.Y, space.Width, child_size.Height, BoundsSpecified.None); space.Y += child.Height; space.Height -= child.Height; break; case DockStyle.Right: if (child.AutoSizeInternal) { child_size = child.GetPreferredSize(new Size(0, space.Height)); } child.SetBoundsInternal(space.Right - child_size.Width, space.Y, child_size.Width, space.Height, BoundsSpecified.None); space.Width -= child.Width; break; case DockStyle.Bottom: if (child.AutoSizeInternal) { child_size = child.GetPreferredSize(new Size(space.Width, 0)); } child.SetBoundsInternal(space.Left, space.Bottom - child_size.Height, space.Width, child_size.Height, BoundsSpecified.None); space.Height -= child.Height; break; case DockStyle.Fill: child.SetBoundsInternal(space.Left, space.Top, space.Width, space.Height, BoundsSpecified.None); break; } } // MdiClient gets whatever space is left if (mdi != null) { mdi.SetBoundsInternal(space.Left, space.Top, space.Width, space.Height, BoundsSpecified.None); } }