Ejemplo n.º 1
0
        private Rectangle GetContolDragDrawRectangle(DockControlContainer container, DockingControl control, Point pointInControl)
        {
            Rectangle rectangleToDraw = Rectangle.Empty;

            Rectangle containerRectangle = control.RectangleToClient(container.RectangleToScreen(container.ClientRectangle));
            Rectangle clientRectangle    = control.ClientRectangle;

            int index = container.DockedControlList.IndexOf(control);

            DockingControl controlBefore = GetControlBefore(container, index);
            DockingControl controlAfter  = GetControlAfter(container, index);

            Rectangle bounds       = control.Bounds;
            Rectangle beforeBounds = (controlBefore == null) ? Rectangle.Empty : controlBefore.Bounds;
            Rectangle afterBounds  = (controlAfter == null) ? Rectangle.Empty : controlAfter.Bounds;

            switch (container.Dock)
            {
            case DockStyle.Left:
            case DockStyle.Right:
                if (container.Tabbed)
                {
                    rectangleToDraw = clientRectangle;
                }
                else if (pointInControl.Y < clientRectangle.Y + (clientRectangle.Height / 2))
                {
                    if (controlBefore == null)
                    {
                        rectangleToDraw         = clientRectangle;
                        rectangleToDraw.Height /= 2;
                    }
                    else
                    {
                        rectangleToDraw = new Rectangle(
                            beforeBounds.Left, beforeBounds.Top + (beforeBounds.Height / 2),
                            beforeBounds.Right, (bounds.Top + (bounds.Height / 2)) - (beforeBounds.Top + (beforeBounds.Height / 2)));

                        rectangleToDraw = control.RectangleToClient(container.RectangleToScreen(rectangleToDraw));
                    }
                }
                else
                {
                    if (controlAfter == null)
                    {
                        rectangleToDraw         = clientRectangle;
                        rectangleToDraw.Y       = clientRectangle.Bottom - (clientRectangle.Height / 2);
                        rectangleToDraw.Height /= 2;
                    }
                    else
                    {
                        rectangleToDraw = new Rectangle(
                            bounds.Left, bounds.Top + (bounds.Height / 2),
                            bounds.Right, (afterBounds.Top + (afterBounds.Height / 2)) - (bounds.Top + (bounds.Height / 2)));

                        rectangleToDraw = control.RectangleToClient(container.RectangleToScreen(rectangleToDraw));
                    }
                }

                break;

            case DockStyle.Bottom:
            case DockStyle.Top:
                if (container.Tabbed)
                {
                    rectangleToDraw = clientRectangle;
                }
                else if (pointInControl.X < clientRectangle.X + (clientRectangle.Width / 2))
                {
                    if (controlBefore == null)
                    {
                        rectangleToDraw        = clientRectangle;
                        rectangleToDraw.Width /= 2;
                    }
                    else
                    {
                        rectangleToDraw = new Rectangle(
                            beforeBounds.Left + (beforeBounds.Width / 2), beforeBounds.Top,
                            (bounds.Left + (bounds.Width / 2)) - (beforeBounds.Left + (beforeBounds.Width / 2)), beforeBounds.Height);

                        rectangleToDraw = control.RectangleToClient(container.RectangleToScreen(rectangleToDraw));
                    }
                }
                else
                {
                    if (controlAfter == null)
                    {
                        rectangleToDraw        = clientRectangle;
                        rectangleToDraw.X      = clientRectangle.Right - (clientRectangle.Width / 2);
                        rectangleToDraw.Width /= 2;
                    }
                    else
                    {
                        rectangleToDraw = new Rectangle(
                            bounds.Left + (bounds.Width / 2), bounds.Top,
                            (afterBounds.Left + (afterBounds.Width / 2)) - (bounds.Left + (bounds.Width / 2)), bounds.Height);

                        rectangleToDraw = control.RectangleToClient(container.RectangleToScreen(rectangleToDraw));
                    }
                }

                break;

            default:
                break;
            }

            return(rectangleToDraw);
        }