/// <summary> /// Invokes a drag event that accepts a valid position for docking. /// </summary> /// <returns>Returns the target docking container.</returns> internal DockContainer ConfirmDock() { DockEventArgs e = new DockEventArgs(new Point(MousePosition.X, MousePosition.Y), this.dockType, true); if (DragWindow != null) DragWindow(this, e); return e.Target; }
/// <summary> /// Invokes the drag event and adjusts the size and location if a valid docking position was received. /// This method is only used by explicit drag windows (see flag). /// </summary> internal void MoveWindow() { if ((this.DragWindow != null) && isDragWindow) { dragTarget = null; DockEventArgs e = new DockEventArgs(new Point(MousePosition.X, MousePosition.Y), this.dockType, false); this.DragWindow(this, e); dragTarget = e.Target; if (dragTarget != null) { this.Size = dragTarget.Size; if (dragTarget.Parent != null) this.Location = dragTarget.RectangleToScreen(dragTarget.ClientRectangle).Location; else this.Location = dragTarget.Location; } } }
/// <summary> /// The DragWindow event handler for dockable windows. /// Used to enable a DockWindow to send its position changes to this container. /// Calls recursively all DragWindow event handlers of the child containers. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">An DockEventArgs that contains the docking data.</param> public void DragWindow(object sender, DockEventArgs e) { try { // First, check if the given point is in the current tree. if (!HitTest(e.Point)) return; // Then, check if the container is dockable at all. if (e.DockType == DockContainerType.None) return; // Then test all containers. foreach (DockContainer c in containerList) { c.DragWindow(sender, e); if (e.Target != null) return; } if (containerList.Count != 0) return; // Then test itself. DockWindow wnd = sender as DockWindow; e.Target = GetTarget(wnd.Size, e.DockType, e.Point); if ((e.Target != null) && (e.Release)) { if (panelList.Contains(wnd.ControlContainer) && (panelList.Count == 1)) { e.Target = this; return; } // Dock the container, if needed. if (!containerList.Contains(e.Target) && (e.Target != this)) { // Create new container and fill it with own panels or containers. DockContainer cont = new DockContainer(); cont.removeable = removeable; removeable = true; cont.DockBorder = dockBorder; cont.DockType = dockType; disableOnControlRemove = true; while (containerList.Count > 0) cont.Controls.Add(containerList[0] as DockContainer); disableOnControlRemove = false; containerList.Add(cont); DockPanel temp = ActivePanel; while (panelList.Count > 0) cont.Controls.Add(panelList[0] as DockPanel); cont.ActivePanel = temp; this.Controls.Add(cont); cont.Dock = DockStyle.Fill; // Add the container to the list object. containerList.Add(e.Target); this.Controls.Add(e.Target); } // Add the panel. e.Target.AddPanel(wnd, e.Point); // Set focus. this.TopLevelControl.BringToFront(); this.TopLevelControl.Invalidate(true); e.Target.ActivePanel.Focus(); } } catch (Exception ex) { Console.WriteLine(ex.Message); } }