Exemple #1
0
        // Lay out the children in this control non-uniformly.
        private void NonUniformLayout()
        {
            ControlCollection controls = Controls;
            int     count, index;
            Control stretch;
            Control child;
            int     posn, posn2;
            Size    clientSize;
            Size    childSize;

            // Find the control to be stretched.
            if (stretchControl != null && stretchControl.Visible)
            {
                stretch = stretchControl;
            }
            else
            {
                stretch = null;
                foreach (Control child1 in controls)
                {
                    if (child1.Visible)
                    {
                        stretch = child1;
                    }
                }
                if (stretch == null)
                {
                    // Abort layout - none of the children are visible.
                    return;
                }
            }

            // Lay out the children before the stretched control.
            count      = controls.Count;
            index      = 0;
            posn       = margin;
            clientSize = ClientSize;
            while (index < count)
            {
                child = controls[index];
                if (child == stretch)
                {
                    break;
                }
                if (child.Visible)
                {
                    childSize = HBoxLayout.GetRecommendedSize(child);
                    child.SetBounds
                        (margin, posn, clientSize.Width - 2 * margin,
                        childSize.Height);
                    posn += childSize.Height + spacing;
                }
                ++index;
            }

            // Lay out the children after the stretched control.
            posn2 = clientSize.Height - margin;
            index = count - 1;
            while (index >= 0)
            {
                child = controls[index];
                if (child == stretch)
                {
                    break;
                }
                if (child.Visible)
                {
                    childSize = HBoxLayout.GetRecommendedSize(child);
                    posn2    -= childSize.Height;
                    child.SetBounds
                        (margin, posn2, clientSize.Width - 2 * margin,
                        childSize.Height);
                    posn2 -= spacing;
                }
                --index;
            }

            // Lay out the stretched control.
            if (posn2 < posn)
            {
                posn2 = posn;
            }
            stretch.SetBounds
                (margin, posn, clientSize.Width - 2 * margin,
                posn2 - posn);
        }
Exemple #2
0
        // Lay out the children in this control.
        protected override void OnLayout(LayoutEventArgs e)
        {
            int[]   columnOffsets = new int [columns];
            int[]   columnWidths = new int [columns];
            int[]   rowOffsets = new int [rows];
            int[]   rowHeights = new int [rows];
            int     x, y;
            Control child;
            int     posnLower, posnUpper;
            Size    childSize;

            // Compute the offset and width of all columns.
            posnLower = margin;
            posnUpper = ClientSize.Width - margin;
            for (x = 0; x < stretchColumn; ++x)
            {
                columnOffsets[x] = posnLower;
                columnWidths[x]  = 0;
                for (y = 0; y < rows; ++y)
                {
                    child = GetControl(x, y);
                    if (child != null && child.visible)
                    {
                        childSize = HBoxLayout.GetRecommendedSize(child);
                        if (childSize.Width > columnWidths[x])
                        {
                            columnWidths[x] = childSize.Width;
                        }
                    }
                }
                posnLower += columnWidths[x] + colSpacing;
            }
            for (x = columns - 1; x > stretchColumn; --x)
            {
                columnWidths[x] = 0;
                for (y = 0; y < rows; ++y)
                {
                    child = GetControl(x, y);
                    if (child != null && child.visible)
                    {
                        childSize = HBoxLayout.GetRecommendedSize(child);
                        if (childSize.Width > columnWidths[x])
                        {
                            columnWidths[x] = childSize.Width;
                        }
                    }
                }
                posnUpper       -= columnWidths[x];
                columnOffsets[x] = posnUpper;
                posnUpper       -= colSpacing;
            }
            columnOffsets[stretchColumn] = posnLower;
            columnWidths[stretchColumn]  = posnUpper - posnLower;

            // Compute the offset and height of all rows.
            posnLower = margin;
            posnUpper = ClientSize.Height - margin;
            for (y = 0; y < stretchRow; ++y)
            {
                rowOffsets[y] = posnLower;
                rowHeights[y] = 0;
                for (x = 0; x < columns; ++x)
                {
                    child = GetControl(x, y);
                    if (child != null && child.visible)
                    {
                        childSize = HBoxLayout.GetRecommendedSize(child);
                        if (childSize.Height > rowHeights[y])
                        {
                            rowHeights[y] = childSize.Height;
                        }
                    }
                }
                posnLower += rowHeights[y] + rowSpacing;
            }
            for (y = rows - 1; y > stretchRow; --y)
            {
                rowHeights[y] = 0;
                for (x = 0; x < columns; ++x)
                {
                    child = GetControl(x, y);
                    if (child != null && child.visible)
                    {
                        childSize = HBoxLayout.GetRecommendedSize(child);
                        if (childSize.Height > rowHeights[y])
                        {
                            rowHeights[y] = childSize.Height;
                        }
                    }
                }
                posnUpper    -= rowHeights[y];
                rowOffsets[y] = posnUpper;
                posnUpper    -= rowSpacing;
            }
            rowOffsets[stretchRow] = posnLower;
            rowHeights[stretchRow] = posnUpper - posnLower;

            // Place the controls in their final locations.
            for (y = 0; y < rows; ++y)
            {
                for (x = 0; x < columns; ++x)
                {
                    child = GetControl(x, y);
                    if (child != null && child.visible)
                    {
                        child.SetBounds
                            (columnOffsets[x], rowOffsets[y],
                            columnWidths[x], rowHeights[y]);
                    }
                }
            }
        }