/// <summary> /// Adjusts the size of children with the AutoSize property, except if they are docked. /// </summary> /// <param name="parent">The parent control whose children are to be adjusted.</param> private static void LayoutAutoSizedChildren(IControlCollectionOwner parent) { foreach (Control child in parent.Controls) { if (!child.Visible || child.LayoutType == LayoutType.Dock || !child.AutoSize) { continue; } AnchorStyles anchor = child.Anchor; Size preferredsize = child.GetPreferredSize(child.Size); if (((anchor & AnchorStyles.Left) != 0) || ((anchor & AnchorStyles.Right) == 0)) { child.DistRight += child.Width - preferredsize.Width; } if (((anchor & AnchorStyles.Top) != 0) || ((anchor & AnchorStyles.Bottom) == 0)) { child.DistBottom += child.Height - preferredsize.Height; } child.SetBounds(child.Left, child.Top, preferredsize.Width, preferredsize.Height, BoundsSpecified.None); } }
/// <summary> /// Fit each control into its corresponding position in the grid. /// </summary> /// <param name="parent">The parent control.</param> /// <param name="settings">The layout settings.</param> /// <param name="columns">The number of columns.</param> /// <param name="rows">The number of rows.</param> /// <returns>A matrix with the controls in their corresponding positions according to the settings.</returns> private Control[,] CalculateControlLocations(IControlCollectionOwner parent, TableLayoutSettings settings, int columns, int rows) { var grid = new Control[columns, rows]; // Assert consistency Debug.Assert(parent.Controls.Count <= columns * rows, string.Format("{0}: Consistency Error, There are more controls than empty spaces", this)); // First place all controls that have an explicit col/row foreach (Control child in parent.Controls) { int col = settings.GetColumn(child); int row = settings.GetRow(child); // Assert consistency Debug.Assert(col >= 0 && col < columns && row >= 0 && row < rows, string.Format("{0}: Consistency Error, A control has an invalid space assigned", this)); // Assert consistency Debug.Assert(grid[col, row] == null, string.Format("{0}: Consistency Error, There are two controls assigned to the same cell", this)); grid[col, row] = child; } return(grid); }
/// <summary> /// Initializes a new instance of the ControlCollection class. /// </summary> /// <param name="owner">The parent of the collection.</param> public ControlCollection(IControlCollectionOwner owner) { this.Owner = owner; this.zorderList = new List <Control>(); }