Example #1
0
        void LayoutAutoSizedChildren(Control parent, Control[] controls)
        {
            for (int i = 0; i < controls.Length; i++)
            {
                int left;
                int top;

                Control child = controls[i];
                if (!child.VisibleInternal ||
                    child.ControlLayoutType == Control.LayoutType.Dock ||
                    !child.AutoSize)
                {
                    continue;
                }

                AnchorStyles anchor = child.Anchor;
                left = child.Left;
                top  = child.Top;

                Size preferredsize = GetPreferredControlSize(child);

                if (((anchor & AnchorStyles.Left) != 0) || ((anchor & AnchorStyles.Right) == 0))
                {
                    child.dist_right += child.Width - preferredsize.Width;
                }
                if (((anchor & AnchorStyles.Top) != 0) || ((anchor & AnchorStyles.Bottom) == 0))
                {
                    child.dist_bottom += child.Height - preferredsize.Height;
                }

                child.SetBoundsInternal(left, top, preferredsize.Width, preferredsize.Height, BoundsSpecified.None);
            }
        }
Example #2
0
        void LayoutAutoSizeContainer(Control container)
        {
            int left;
            int top;
            int width;
            int height;

            if (!container.VisibleInternal || container.ControlLayoutType == Control.LayoutType.Dock || !container.AutoSize)
            {
                return;
            }

            left = container.Left;
            top  = container.Top;

            Size preferredsize = container.PreferredSize;

            if (container.GetAutoSizeMode() == AutoSizeMode.GrowAndShrink)
            {
                width  = preferredsize.Width;
                height = preferredsize.Height;
            }
            else
            {
                width  = container.ExplicitBounds.Width;
                height = container.ExplicitBounds.Height;
                if (preferredsize.Width > width)
                {
                    width = preferredsize.Width;
                }
                if (preferredsize.Height > height)
                {
                    height = preferredsize.Height;
                }
            }

            // Sanity
            if (width < container.MinimumSize.Width)
            {
                width = container.MinimumSize.Width;
            }

            if (height < container.MinimumSize.Height)
            {
                height = container.MinimumSize.Height;
            }

            if (container.MaximumSize.Width != 0 && width > container.MaximumSize.Width)
            {
                width = container.MaximumSize.Width;
            }

            if (container.MaximumSize.Height != 0 && height > container.MaximumSize.Height)
            {
                height = container.MaximumSize.Height;
            }

            container.SetBoundsInternal(left, top, width, height, BoundsSpecified.None);
        }
Example #3
0
        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);
            }
        }
Example #4
0
        void LayoutAnchoredChildren(Control parent, Control[] controls)
        {
            Rectangle space = parent.ClientRectangle;

            for (int i = 0; i < controls.Length; i++)
            {
                int left;
                int top;
                int width;
                int height;

                Control child = controls[i];

                if (!child.VisibleInternal ||
                    child.ControlLayoutType == Control.LayoutType.Dock)
                {
                    continue;
                }

                AnchorStyles anchor = child.Anchor;

                left = child.Left;
                top  = child.Top;

                width  = child.Width;
                height = child.Height;

                if ((anchor & AnchorStyles.Right) != 0)
                {
                    if ((anchor & AnchorStyles.Left) != 0)
                    {
                        width = space.Width - child.dist_right - left;
                    }
                    else
                    {
                        left = space.Width - child.dist_right - width;
                    }
                }
                else if ((anchor & AnchorStyles.Left) == 0)
                {
                    // left+=diff_width/2 will introduce rounding errors (diff_width removed from svn after r51780)
                    // This calculates from scratch every time:
                    left             = left + (space.Width - (left + width + child.dist_right)) / 2;
                    child.dist_right = space.Width - (left + width);
                }

                if ((anchor & AnchorStyles.Bottom) != 0)
                {
                    if ((anchor & AnchorStyles.Top) != 0)
                    {
                        height = space.Height - child.dist_bottom - top;
                    }
                    else
                    {
                        top = space.Height - child.dist_bottom - height;
                    }
                }
                else if ((anchor & AnchorStyles.Top) == 0)
                {
                    // top += diff_height/2 will introduce rounding errors (diff_height removed from after r51780)
                    // This calculates from scratch every time:
                    top = top + (space.Height - (top + height + child.dist_bottom)) / 2;
                    child.dist_bottom = space.Height - (top + height);
                }

                // Sanity
                if (width < 0)
                {
                    width = 0;
                }

                if (height < 0)
                {
                    height = 0;
                }

                child.SetBoundsInternal(left, top, width, height, BoundsSpecified.None);
            }
        }
Example #5
0
		void LayoutAutoSizeContainer (Control container)
		{
			int left;
			int top;
			int width;
			int height;

			if (!container.VisibleInternal || container.ControlLayoutType == Control.LayoutType.Dock || !container.AutoSize)
				return;

			left = container.Left;
			top = container.Top;

			Size preferredsize = container.PreferredSize;

			if (container.GetAutoSizeMode () == AutoSizeMode.GrowAndShrink) {
				width = preferredsize.Width;
				height = preferredsize.Height;
			} else {
				width = container.ExplicitBounds.Width;
				height = container.ExplicitBounds.Height;
				if (preferredsize.Width > width)
					width = preferredsize.Width;
				if (preferredsize.Height > height)
					height = preferredsize.Height;
			}

			// Sanity
			if (width < container.MinimumSize.Width)
				width = container.MinimumSize.Width;

			if (height < container.MinimumSize.Height)
				height = container.MinimumSize.Height;

			if (container.MaximumSize.Width != 0 && width > container.MaximumSize.Width)
				width = container.MaximumSize.Width;

			if (container.MaximumSize.Height != 0 && height > container.MaximumSize.Height)
				height = container.MaximumSize.Height;

			container.SetBoundsInternal (left, top, width, height, BoundsSpecified.None);
		}
Example #6
0
        private void LayoutControls(TableLayoutPanel panel)
        {
            TableLayoutSettings settings = panel.LayoutSettings;

            int border_width = TableLayoutPanel.GetCellBorderWidth(panel.CellBorderStyle);

            int columns = panel.actual_positions.GetLength(0);
            int rows    = panel.actual_positions.GetLength(1);

            Point_ current_pos = new Point_(panel.DisplayRectangle.Left + border_width, panel.DisplayRectangle.Top + border_width);

            for (int y = 0; y < rows; y++)
            {
                for (int x = 0; x < columns; x++)
                {
                    Control c = panel.actual_positions[x, y];

                    if (c != null && c != dummy_control)
                    {
                        Size_ preferred;

                        if (c.AutoSize)
                        {
                            preferred = c.PreferredSize;
                        }
                        else
                        {
                            preferred = c.ExplicitBounds.Size;
                        }

                        int new_x      = 0;
                        int new_y      = 0;
                        int new_width  = 0;
                        int new_height = 0;

                        // Figure out the width of the control
                        int column_width = panel.column_widths[x];

                        for (int i = 1; i < Math.Min(settings.GetColumnSpan(c), panel.column_widths.Length); i++)
                        {
                            column_width += panel.column_widths[x + i];
                        }

                        if (c.Dock == DockStyle.Fill || c.Dock == DockStyle.Top || c.Dock == DockStyle.Bottom || ((c.Anchor & AnchorStyles.Left) == AnchorStyles.Left && (c.Anchor & AnchorStyles.Right) == AnchorStyles.Right))
                        {
                            new_width = column_width - c.Margin.Left - c.Margin.Right;
                        }
                        else
                        {
                            new_width = Math.Min(preferred.Width, column_width - c.Margin.Left - c.Margin.Right);
                        }

                        // Figure out the height of the control
                        int column_height = panel.row_heights[y];

                        for (int i = 1; i < Math.Min(settings.GetRowSpan(c), panel.row_heights.Length); i++)
                        {
                            column_height += panel.row_heights[y + i];
                        }

                        if (c.Dock == DockStyle.Fill || c.Dock == DockStyle.Left || c.Dock == DockStyle.Right || ((c.Anchor & AnchorStyles.Top) == AnchorStyles.Top && (c.Anchor & AnchorStyles.Bottom) == AnchorStyles.Bottom))
                        {
                            new_height = column_height - c.Margin.Top - c.Margin.Bottom;
                        }
                        else
                        {
                            new_height = Math.Min(preferred.Height, column_height - c.Margin.Top - c.Margin.Bottom);
                        }

                        // Figure out the left location of the control
                        if (c.Dock == DockStyle.Left || c.Dock == DockStyle.Fill || (c.Anchor & AnchorStyles.Left) == AnchorStyles.Left)
                        {
                            new_x = current_pos.X + c.Margin.Left;
                        }
                        else if (c.Dock == DockStyle.Right || (c.Anchor & AnchorStyles.Right) == AnchorStyles.Right)
                        {
                            new_x = (current_pos.X + column_width) - new_width - c.Margin.Right;
                        }
                        else                            // (center control)
                        {
                            new_x = (current_pos.X + (column_width - c.Margin.Left - c.Margin.Right) / 2) + c.Margin.Left - (new_width / 2);
                        }

                        // Figure out the top location of the control
                        if (c.Dock == DockStyle.Top || c.Dock == DockStyle.Fill || (c.Anchor & AnchorStyles.Top) == AnchorStyles.Top)
                        {
                            new_y = current_pos.Y + c.Margin.Top;
                        }
                        else if (c.Dock == DockStyle.Bottom || (c.Anchor & AnchorStyles.Bottom) == AnchorStyles.Bottom)
                        {
                            new_y = (current_pos.Y + column_height) - new_height - c.Margin.Bottom;
                        }
                        else                            // (center control)
                        {
                            new_y = (current_pos.Y + (column_height - c.Margin.Top - c.Margin.Bottom) / 2) + c.Margin.Top - (new_height / 2);
                        }

                        c.SetBoundsInternal(new_x, new_y, new_width, new_height, BoundsSpecified.None);
                    }

                    current_pos.Offset(panel.column_widths[x] + border_width, 0);
                }

                current_pos.Offset((-1 * current_pos.X) + border_width + panel.DisplayRectangle.Left, panel.row_heights[y] + border_width);
            }
        }
Example #7
0
        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);
            }
        }