private void Debug_VerifyAlignment(IArrangedElement container, FlowDirection flowDirection) { #if DEBUG //We cannot apply any of these checks @ design-time since dragging new children into a FlowLayoutPanel //will attempt to set the children at the mouse position when the child was dropped - we rely on the controil //to reposition the children once added. Control flp = container as Control; if (flp != null && flp.Site != null && flp.Site.DesignMode) { return; } //check to see if the first element is in its right place Padding margin = CommonProperties.GetMargin(container.Children[0]); switch (flowDirection) { case FlowDirection.LeftToRight: case FlowDirection.TopDown: Debug.Assert(container.Children[0].Bounds.Y == margin.Top + container.DisplayRectangle.Y); Debug.Assert(container.Children[0].Bounds.X == margin.Left + container.DisplayRectangle.X); break; case FlowDirection.RightToLeft: Debug.Assert(container.Children[0].Bounds.X == container.DisplayRectangle.X + container.DisplayRectangle.Width - container.Children[0].Bounds.Width - margin.Right); Debug.Assert(container.Children[0].Bounds.Y == margin.Top + container.DisplayRectangle.Y); break; case FlowDirection.BottomUp: Debug.Assert(container.Children[0].Bounds.Y == container.DisplayRectangle.Y + container.DisplayRectangle.Height - container.Children[0].Bounds.Height - margin.Bottom); Debug.Assert(container.Children[0].Bounds.X == margin.Left + container.DisplayRectangle.X); break; } //next check to see if everything is in bound ArrangedElementCollection collection = container.Children; for (int i = 1; i < collection.Count; i++) { switch (flowDirection) { case FlowDirection.LeftToRight: case FlowDirection.TopDown: Debug.Assert(collection[i].Bounds.Y >= container.DisplayRectangle.Y); Debug.Assert(collection[i].Bounds.X >= container.DisplayRectangle.X); break; case FlowDirection.RightToLeft: Debug.Assert(collection[i].Bounds.Y >= container.DisplayRectangle.Y); Debug.Assert(collection[i].Bounds.X + collection[i].Bounds.Width <= container.DisplayRectangle.X + container.DisplayRectangle.Width); break; case FlowDirection.BottomUp: Debug.Assert(collection[i].Bounds.Y + collection[i].Bounds.Height <= container.DisplayRectangle.Y + container.DisplayRectangle.Height); Debug.Assert(collection[i].Bounds.X >= container.DisplayRectangle.X); break; } } #endif }
private static Size GetAnchorPreferredSize(IArrangedElement container) { Size empty = Size.Empty; for (int i = container.Children.Count - 1; i >= 0; i--) { IArrangedElement element = container.Children[i]; if (!CommonProperties.GetNeedsDockLayout(element) && element.ParticipatesInLayout) { AnchorStyles anchor = GetAnchor(element); Padding margin = CommonProperties.GetMargin(element); Rectangle rectangle = LayoutUtils.InflateRect(GetCachedBounds(element), margin); if (IsAnchored(anchor, AnchorStyles.Left) && !IsAnchored(anchor, AnchorStyles.Right)) { empty.Width = Math.Max(empty.Width, rectangle.Right); } if (!IsAnchored(anchor, AnchorStyles.Bottom)) { empty.Height = Math.Max(empty.Height, rectangle.Bottom); } if (IsAnchored(anchor, AnchorStyles.Right)) { Rectangle rectangle2 = GetAnchorDestination(element, Rectangle.Empty, true); if (rectangle2.Width < 0) { empty.Width = Math.Max(empty.Width, rectangle.Right + rectangle2.Width); } else { empty.Width = Math.Max(empty.Width, rectangle2.Right); } } if (IsAnchored(anchor, AnchorStyles.Bottom)) { Rectangle rectangle3 = GetAnchorDestination(element, Rectangle.Empty, true); if (rectangle3.Height < 0) { empty.Height = Math.Max(empty.Height, rectangle.Bottom + rectangle3.Height); } else { empty.Height = Math.Max(empty.Height, rectangle3.Bottom); } } } } return(empty); }
private static Size GetAnchorPreferredSize(IArrangedElement container) { Size prefSize = Size.Empty; ArrangedElementCollection children = container.Children; for (int i = children.Count - 1; i >= 0; i--) { IArrangedElement element = container.Children[i]; if (!CommonProperties.GetNeedsDockLayout(element) && element.ParticipatesInLayout) { AnchorStyles anchor = GetAnchor(element); Padding margin = CommonProperties.GetMargin(element); Rectangle elementSpace = LayoutUtils.InflateRect(GetCachedBounds(element), margin); if (IsAnchored(anchor, AnchorStyles.Left) && !IsAnchored(anchor, AnchorStyles.Right)) { // If we are anchored to the left we make sure the container is large enough not to clip us // (unless we are right anchored, in which case growing the container will just resize us.) prefSize.Width = Math.Max(prefSize.Width, elementSpace.Right); } if (!IsAnchored(anchor, AnchorStyles.Bottom)) { // If we are anchored to the top we make sure the container is large enough not to clip us // (unless we are bottom anchored, in which case growing the container will just resize us.) prefSize.Height = Math.Max(prefSize.Height, elementSpace.Bottom); } if (IsAnchored(anchor, AnchorStyles.Right)) { // If we are right anchored, see what the anchor distance between our right edge and // the container is, and make sure our container is large enough to accomodate us. Rectangle anchorDest = GetAnchorDestination(element, Rectangle.Empty, /*measureOnly=*/ true); if (anchorDest.Width < 0) { prefSize.Width = Math.Max(prefSize.Width, elementSpace.Right + anchorDest.Width); } else { prefSize.Width = Math.Max(prefSize.Width, anchorDest.Right); } } if (IsAnchored(anchor, AnchorStyles.Bottom)) { // If we are right anchored, see what the anchor distance between our right edge and // the container is, and make sure our container is large enough to accomodate us. Rectangle anchorDest = GetAnchorDestination(element, Rectangle.Empty, /*measureOnly=*/ true); if (anchorDest.Height < 0) { prefSize.Height = Math.Max(prefSize.Height, elementSpace.Bottom + anchorDest.Height); } else { prefSize.Height = Math.Max(prefSize.Height, anchorDest.Bottom); } } } } return(prefSize); }