private Rectangle GetContainerDragDrawRectangle(DockControlContainer container, Point pointInScreen) { Point pointInControl = container.PointToClient(pointInScreen); Rectangle clientRectangle = container.ClientRectangle; Rectangle rectangleToDraw = Rectangle.Empty; Rectangle containerRectangle = container.RectangleToScreen(container.ClientRectangle); switch (container.Dock) { case DockStyle.Top: case DockStyle.Bottom: if (pointInControl.Y > clientRectangle.Y && pointInControl.Y < clientRectangle.Y + DockingBarSize) { rectangleToDraw = containerRectangle; rectangleToDraw.Height = DockingBarSize; } else if (pointInControl.Y < clientRectangle.Bottom && pointInControl.Y > clientRectangle.Bottom - DockingBarSize) { rectangleToDraw = containerRectangle; rectangleToDraw.Y = containerRectangle.Bottom - DockingBarSize; rectangleToDraw.Height = DockingBarSize; } break; case DockStyle.Left: case DockStyle.Right: if (pointInControl.X > clientRectangle.X && pointInControl.X < clientRectangle.X + DockingBarSize) { rectangleToDraw = containerRectangle; rectangleToDraw.Width = DockingBarSize; } else if (pointInControl.X < clientRectangle.Right && pointInControl.X > clientRectangle.Right - DockingBarSize) { rectangleToDraw = containerRectangle; rectangleToDraw.X = containerRectangle.Right - DockingBarSize; rectangleToDraw.Width = DockingBarSize; } break; default: break; } return(rectangleToDraw); }
private void _toolStripCaption_CaptionDrag(object sender, MouseEventArgs e) { Point pointInScreen = this.PointToScreen(e.Location); DockControlContainer container = _manager.GetContainerAtPoint(_manager.PointToClient(pointInScreen)); if (container == null) { Rectangle dragRectangle = DockControlHelpers.GetDropXorDragRect(_manager, pointInScreen, DockingBarSize); if (!dragRectangle.IsEmpty) { _dragger.SetRectangle(_manager.RectangleToScreen(dragRectangle)); return; } } else { Rectangle rectangleToDraw = GetContainerDragDrawRectangle(container, pointInScreen); if (!rectangleToDraw.IsEmpty) { _dragger.SetRectangle(rectangleToDraw); return; } if (container.Tabbed) { _dragger.SetRectangle(container.RectangleToScreen(container.ClientRectangle)); return; } else { DockingControl control = container.GetDockingControlAtPoint(container.PointToClient(pointInScreen)); if (control != null) { Point pointInControl = control.PointToClient(pointInScreen); rectangleToDraw = GetContolDragDrawRectangle(container, control, pointInControl); _dragger.SetRectangle(control.RectangleToScreen(rectangleToDraw)); return; } } } _dragger.MoveTo(e.Location); }
private void DockControl(Point dropPoint, DockControlContainer container, int dimension) { Point containerLocalDropPoint = container.PointToClient(PointToScreen(dropPoint)); int index = 0; DockedControlCollection controls = container.DockedControls as DockedControlCollection; foreach (DockingControl child in controls) { Rectangle bounds = child.Bounds; switch (container.Dock) { case DockStyle.Top: case DockStyle.Bottom: if (bounds.Right >= containerLocalDropPoint.X) { if (containerLocalDropPoint.X < (bounds.Left + bounds.Right) / 2) { container.DockControl(this, index, dimension); return; } } break; case DockStyle.Left: case DockStyle.Right: if (bounds.Bottom >= containerLocalDropPoint.Y) { if (containerLocalDropPoint.Y < (bounds.Top + bounds.Bottom) / 2) { container.DockControl(this, index, dimension); return; } } break; } index += 1; } container.DockControl(this, container.DockedControlList.Count, dimension); }