Пример #1
0
        protected void ResizeDirection(int remainder, ZoneCollection zcAlpha, ZoneCollection zcBeta, Direction dir)
        {
            bool alter;
            int available;
            int half1, half2;

            // Keep going till all space found or nowhere to get it from
            while((remainder > 0) && ((zcAlpha.Count > 0) || (zcBeta.Count > 0)))
            {
                if (dir == Direction.Horizontal)
                {
                    _firstHalfWidth = (_firstHalfWidth != true);
                    alter = _firstHalfWidth;
                }
                else
                {
                    _firstHalfHeight = (_firstHalfHeight != true);
                    alter = _firstHalfHeight;
                }

                // Alternate between left and right getting the remainder
                if (alter)
                {
                    half1 = (remainder / 2) + 1;
                    half2 = remainder - half1;
                }
                else
                {
                    half2 = (remainder / 2) + 1;
                    half1 = remainder - half2;
                }

                // Any Zone of the left to use?
                if (zcAlpha.Count > 0)
                {
                    Zone z = zcAlpha[0];

                    // Find how much space it can offer up
                    if (dir == Direction.Horizontal)
                        available = z.Width - z.MinimumWidth;
                    else
                        available = z.Height - z.MinimumHeight;

                    if (available > 0)
                    {
                        // Only take away the maximum we need
                        if (available > half1)
                            available = half1;
                        else
                            zcAlpha.Remove(z);

                        // Resize the control accordingly
                        if (dir == Direction.Horizontal)
                            z.Width = z.Width - available;
                        else
                            z.Height = z.Height - available;

                        // Reduce total amount left to allocate
                        remainder -= available;
                    }
                    else
                        zcAlpha.Remove(z);
                }

                // Any Zone of the left to use?
                if (zcBeta.Count > 0)
                {
                    Zone z = zcBeta[0];

                    // Find how much space it can offer up
                    if (dir == Direction.Horizontal)
                        available = z.Width - z.MinimumWidth;
                    else
                        available = z.Height - z.MinimumHeight;

                    if (available > 0)
                    {
                        // Only take away the maximum we need
                        if (available > half2)
                            available = half2;
                        else
                            zcBeta.Remove(z);

                        // Resize the control accordingly
                        if (dir == Direction.Horizontal)
                            z.Width = z.Width - available;
                        else
                            z.Height = z.Height - available;

                        // Reduce total amount left to allocate
                        remainder -= available;
                    }
                    else
                        zcBeta.Remove(z);
                }
            }
        }
Пример #2
0
        protected void OnContainerResized(object sender, EventArgs e)
        {
            if (_autoResize)
            {
                Rectangle inner = InnerResizeRectangle(null);

                // Shrink by the minimum size
                inner.Width -= _innerMinimum.Width;
                inner.Height -= _innerMinimum.Height;

                Form f = _container as Form;

                // If the container is a Form then ignore resizing because of becoming Minimized
                if ((f == null) || ((f != null) && (f.WindowState != FormWindowState.Minimized)))
                {
                    if ((inner.Width < 0) || (inner.Height < 0))
                    {
                        _container.SuspendLayout();

                        ZoneCollection zcLeft = new ZoneCollection();
                        ZoneCollection zcRight = new ZoneCollection();
                        ZoneCollection zcTop = new ZoneCollection();
                        ZoneCollection zcBottom = new ZoneCollection();

                        // Construct a list of the docking windows on the left and right edges
                        foreach(Control c in _container.Controls)
                        {
                            Zone z = c as Zone;

                            if (z != null)
                            {
                                switch(z.State)
                                {
                                    case State.DockLeft:
                                        zcLeft.Add(z);
                                        break;
                                    case State.DockRight:
                                        zcRight.Add(z);
                                        break;
                                    case State.DockTop:
                                        zcTop.Add(z);
                                        break;
                                    case State.DockBottom:
                                        zcBottom.Add(z);
                                        break;
                                }
                            }
                        }

                        if (inner.Width < 0)
                            ResizeDirection(-inner.Width, zcLeft, zcRight, Direction.Horizontal);

                        if (inner.Height < 0)
                            ResizeDirection(-inner.Height, zcTop, zcBottom, Direction.Vertical);

                        _container.ResumeLayout();
                    }
                }
            }
        }