public void OpenPanelInCurrentForm(MyPanel PanelToAddToWindow, MainForm FormToAddOn) { RemovePanel(PanelToAddToWindow); FormToAddOn.IOController.AddPanel(PanelToAddToWindow); PanelToAddToWindow.OnOpenedInDifferentForm(FormToAddOn); FlowLayoutEvents.OnMainPanelLayoutChanged(); FormToAddOn.IOController.FlowLayoutEvents.OnMainPanelLayoutChanged(); }
public void StartReLayout(MyPanel SizingPanel, System.Drawing.Point StartLocation) { if (StartLayout != null) { AssociatedForm.Controls.Remove(MainPanel); StartLayout(SizingPanel, MainPanel.VisiblePanels, StartLocation, MainPanel.DockPoints); } }
/// <summary> /// Removes a panel from the content tab control /// </summary> /// <param name="ControlToRemove">The panel to remove from the main tab control</param> public void RemoveContentPanel(MyPanel ControlToRemove) { if (!ControlToRemove.Removed) { ControlToRemove.Removed = true; ControlToRemove.OnPanelClosed(AssociatedForm); } ContentTabControl.RemovePanelFromControl(ControlToRemove); }
/// <summary> /// Adds a panel to the content tab control /// </summary> /// <param name="ControlToAdd">The panel to add within the main tab control</param> public void AddContentPanel(MyPanel ControlToAdd) { ContentTabControl.AddPanelToTabControl(ControlToAdd); if (ControlToAdd.Removed) { ControlToAdd.OnPanelOpened(AssociatedForm); ControlToAdd.Removed = false; } }
/// <summary> /// Removes a panel from the content tab control, triggers the PanelClosed event and re-draws the control. /// </summary> /// <param name="PanelToRemove">The panel to be removed from the tab control</param> public void RemovePanelFromControl(MyPanel PanelToRemove) { if (PanelToRemove.InContentPanel) { PanelsToDisplay.Remove(PanelToRemove); PanelToRemove.InContentPanel = false; PanelToRemove.OnPanelClosed(base.ParentForm); DisplayControls(); } }
/// <summary> /// Opens a panel in a new window /// </summary> /// <param name="PanelToAddToNewWindow">The panel to open in a new window</param> /// <param name="OldForm">The original form on which it was displayed</param> public void OpenInNewWindow(MyPanel PanelToAddToNewWindow, MainForm OldForm) { //Add a new form with a new instance of the IO controller specified by the panel being removed. //This means that the new form matches the type of the panel. this.AddForm(PanelToAddToNewWindow.ParentForm.IOController.GetNew()); int indexOfLastForm = this.Count - 1; //Remove the panel from the old form and add the panel to the new one. OldForm.IOController.RemovePanel(PanelToAddToNewWindow); this[indexOfLastForm].IOController.AddPanel(PanelToAddToNewWindow); //Fire the opened in new form event for the panel. PanelToAddToNewWindow.OnOpenedInDifferentForm(this[indexOfLastForm]); //Show the new form. this[indexOfLastForm].Show(); }
/// <summary> /// Adds a panel to the tab control and re-draws the control. /// </summary> /// <param name="PanelToAdd">The panel to be added to the control.</param> public void AddPanelToTabControl(MyPanel PanelToAdd) { if (!PanelToAdd.InContentPanel) { PanelsToDisplay.Add(PanelToAdd); PanelToAdd.RemoveToolbarButtons(); PanelToAdd.PanelIndex = PanelsToDisplay.Count - 1; PanelToAdd.InContentPanel = true; //Add tool strip button to close the panel. MyToolStripButton ButtonToAdd; ButtonToAdd = new MyToolStripButton(PanelsToDisplay.Count - 1); ButtonToAdd.Text = PanelToAdd.Name; ButtonToAdd.ButtonClicked += tempButton_CustomCheckedChanged; closePanels.DropDownItems.Add(ButtonToAdd); DisplayControls(); } }
/// <summary> /// Updates the rectangle of remaining area on the panel after a control is added /// </summary> /// <param name="addedControl">The control that was added</param> void UpdateRemainingSize(IDockableControl addedControl) { Control controlCopy = (Control)addedControl; if (addedControl.FillStyle == FillStyles.FullHeight) { remainingSize.Width -= controlCopy.Width; if (MyPanel.IsDockedAtLeft(addedControl.DockType)) { remainingSize.Location = new Point(remainingSize.Left + controlCopy.Width, remainingSize.Top); } } if (addedControl.FillStyle == FillStyles.FullWidth) { remainingSize.Height -= controlCopy.Height; if (MyPanel.IsDockedAtLeft(addedControl.DockType)) { remainingSize.Location = new Point(remainingSize.Left, remainingSize.Top + controlCopy.Height); } } }
/// <summary> /// Starts the dynamic drag-drop process on the form by displaying the drag-drop interface. /// Events are subscribed to so that when the panel is clicked again the panel is dropped. /// </summary> /// <param name="panelBeingDragged">The panel that has been selected</param> /// <param name="visibleControls">A list of all visible panels on the form</param> /// <param name="startLocation">The initial click location</param> /// <param name="dockPoints">A dictionary of the available points the panel can be docked to on the form</param> public void StartDragDropLayout(MyPanel panelBeingDragged, List <MyPanel> visibleControls, Point startLocation, Dictionary <DockTypes, Point> dockPoints) { UnlinkFormsFromStartDragDrop(); this.visiblePanels = visibleControls; this.panelBeingRelocated = panelBeingDragged; this.startLocation = startLocation; this.dockPoints = dockPoints; MouseMove += DragDropController_MouseMove; MouseUp += DragDropController_MouseUp; form = panelBeingDragged.ParentForm; collection.AddEventToForms(DropPanelOnCurrentForm); IOController.FlowLayoutEvents.PanelDrag += MyEvents_PanelDrag; rectanglesToDraw.Clear(); dragState = DragState.Drag; StartLayout(); IOController.ShowDynamicLayoutPanel(this); }
public MyContextMenu(MyPanel parent) { _parent = parent; SetupComponents(); }
/// <summary> /// Inserts a panel into the layout lines system, and updates the lines around it. /// </summary> /// <param name="p">The control to add to the layout lines system</param> /// <param name="DockType">The dock type of the control that is added to the system</param> public void AddPanel(Control p, DockTypes DockType) { int leftIndex = 0; int rightIndex = 0; int topIndex = 0; int bottomIndex = 0; int indexToInsertPanelLineAt; Line panelLineToInsert; int[] lineIndicesRestrictingPanel; List <int> lineIndicesToRemove = new List <int>(); Locations horizontalLocationToAddLine, verticalLocationToAddLine; horizontalLocationToAddLine = (MyPanel.IsDockedAtLeft(DockType) ? Locations.Left : Locations.Right); verticalLocationToAddLine = (MyPanel.IsDockedAtTop(DockType) ? Locations.Top : Locations.Bottom); //VERTICAL POSITION lineIndicesRestrictingPanel = GetIndicesOfLinesRestrictingPanel(p, verticalLocationToAddLine); leftIndex = lineIndicesRestrictingPanel[0]; rightIndex = lineIndicesRestrictingPanel[1]; if (leftIndex == rightIndex) { lines[verticalLocationToAddLine].Insert(leftIndex + 1, new Line(lines[verticalLocationToAddLine][leftIndex])); rightIndex = leftIndex + 1; } lines[verticalLocationToAddLine][leftIndex].setEndPointX(p.Left); lines[verticalLocationToAddLine][rightIndex].setStartPointX(p.Right); if (lines[verticalLocationToAddLine][rightIndex].Length == 0) { lineIndicesToRemove.Add(rightIndex); } for (int i = rightIndex - 1; i > leftIndex; i--) { lineIndicesToRemove.Add(i); } if (lines[verticalLocationToAddLine][leftIndex].Length == 0) { lineIndicesToRemove.Add(leftIndex); indexToInsertPanelLineAt = leftIndex; } else { indexToInsertPanelLineAt = leftIndex + 1; } foreach (int index in lineIndicesToRemove) { lines[verticalLocationToAddLine].RemoveAt(index); } lineIndicesToRemove.Clear(); panelLineToInsert = AddLineFromSideOfPanel(p, (verticalLocationToAddLine == Locations.Top ? Locations.Bottom : Locations.Top)); lines[verticalLocationToAddLine].Insert(indexToInsertPanelLineAt, panelLineToInsert); //HORIZONTAL POSITION lineIndicesRestrictingPanel = GetIndicesOfLinesRestrictingPanel(p, horizontalLocationToAddLine); topIndex = lineIndicesRestrictingPanel[0]; bottomIndex = lineIndicesRestrictingPanel[1]; //If only one line index, the same layout line covers the whole of the top of the panel if (topIndex == bottomIndex) { //Add a copy of this line lines[horizontalLocationToAddLine].Insert(topIndex + 1, new Line(lines[horizontalLocationToAddLine][topIndex])); bottomIndex = topIndex + 1; } //Set the end of the left line and start of the right line to the corners of the panel. lines[horizontalLocationToAddLine][topIndex].setEndPointY(p.Top); lines[horizontalLocationToAddLine][bottomIndex].setStartPointY(p.Bottom); //Remove any zero length lines at the bottom of the panel if (lines[horizontalLocationToAddLine][bottomIndex].Length == 0) { lineIndicesToRemove.Add(bottomIndex); } //Set a flag to remove any lines contained within the bounds of the panel for (int lineIndex = bottomIndex - 1; lineIndex > topIndex; lineIndex--) { lineIndicesToRemove.Add(lineIndex); } //Remove zero length lines at the top of the panel if (lines[horizontalLocationToAddLine][topIndex].Length == 0) { lineIndicesToRemove.Add(topIndex); indexToInsertPanelLineAt = topIndex; //If lines to the left are removed, the insertion index is the top index } else { indexToInsertPanelLineAt = topIndex + 1; //Else the insertion index is one above the top index } //Remove the lines marked for removal foreach (int index in lineIndicesToRemove) { lines[horizontalLocationToAddLine].RemoveAt(index); } lineIndicesToRemove.Clear(); //Insert the line based on the edge of the panel panelLineToInsert = AddLineFromSideOfPanel(p, (horizontalLocationToAddLine == Locations.Left ? Locations.Right : Locations.Left)); lines[horizontalLocationToAddLine].Insert(indexToInsertPanelLineAt, panelLineToInsert); }
void UpdatePoints(IDockableControl controlBeingAdded) { Control controlCopy = (Control)controlBeingAdded; //Depending on how the control fills the screen, //update the location of the dock points switch (controlBeingAdded.FillStyle) { case FillStyles.FullWidth: { //Change the locatoin of the dock points that are affected by the control if (MyPanel.IsDockedAtTop(controlBeingAdded.DockType)) { dockPointLocations[DockTypes.TopLeft] = AddHeightToDockPoint(DockTypes.TopLeft, controlCopy.Height); dockPointLocations[DockTypes.Left] = AddHeightToDockPoint(DockTypes.Left, controlCopy.Height); dockPointLocations[DockTypes.Top] = AddHeightToDockPoint(DockTypes.Top, controlCopy.Height); dockPointLocations[DockTypes.None] = AddHeightToDockPoint(DockTypes.None, controlCopy.Height); dockPointLocations[DockTypes.TopRight] = AddHeightToDockPoint(DockTypes.TopRight, controlCopy.Height); dockPointLocations[DockTypes.Right] = AddHeightToDockPoint(DockTypes.Right, controlCopy.Height); dockPointLocations[DockTypes.Top2] = AddHeightToDockPoint(DockTypes.Top2, controlCopy.Height); } else { dockPointLocations[DockTypes.BottomLeft] = AddHeightToDockPoint(DockTypes.BottomLeft, -controlCopy.Height); dockPointLocations[DockTypes.Bottom] = AddHeightToDockPoint(DockTypes.Bottom, -controlCopy.Height); dockPointLocations[DockTypes.BottomRight] = AddHeightToDockPoint(DockTypes.BottomRight, -controlCopy.Height); dockPointLocations[DockTypes.Bottom2] = AddHeightToDockPoint(DockTypes.Bottom2, -controlCopy.Height); } break; } case FillStyles.FullHeight: { if (MyPanel.IsDockedAtLeft(controlBeingAdded.DockType)) { dockPointLocations[DockTypes.TopLeft] = AddWidthToDockPoint(DockTypes.TopLeft, controlCopy.Width); dockPointLocations[DockTypes.Left] = AddWidthToDockPoint(DockTypes.Left, controlCopy.Width); dockPointLocations[DockTypes.BottomLeft] = AddWidthToDockPoint(DockTypes.BottomLeft, controlCopy.Width); dockPointLocations[DockTypes.Top] = AddWidthToDockPoint(DockTypes.Top, controlCopy.Width); dockPointLocations[DockTypes.None] = AddWidthToDockPoint(DockTypes.None, controlCopy.Width); dockPointLocations[DockTypes.Bottom] = AddWidthToDockPoint(DockTypes.Bottom, controlCopy.Width); } else { dockPointLocations[DockTypes.TopRight] = AddWidthToDockPoint(DockTypes.TopRight, -controlCopy.Width); dockPointLocations[DockTypes.Right] = AddWidthToDockPoint(DockTypes.Right, -controlCopy.Width); dockPointLocations[DockTypes.BottomRight] = AddWidthToDockPoint(DockTypes.BottomRight, -controlCopy.Width); dockPointLocations[DockTypes.Top2] = AddWidthToDockPoint(DockTypes.Top2, -controlCopy.Width); dockPointLocations[DockTypes.Bottom2] = AddWidthToDockPoint(DockTypes.Bottom2, -controlCopy.Width); } break; } case FillStyles.None: { //If the panel being added will affect the dock point: if ((controlBeingAdded.DockPointLocation == dockPointLocations[DockTypes.TopLeft]) || (controlBeingAdded.DockPointLocation == dockPointLocations[DockTypes.Left]) || (controlBeingAdded.DockPointLocation == dockPointLocations[DockTypes.None])) { dockPointLocations[DockTypes.TopLeft] = AddHeightToDockPoint(DockTypes.TopLeft, controlCopy.Height); dockPointLocations[DockTypes.Left] = AddHeightToDockPoint(DockTypes.Left, controlCopy.Height); dockPointLocations[DockTypes.None] = AddHeightToDockPoint(DockTypes.None, controlCopy.Height); } if (controlBeingAdded.DockPointLocation == dockPointLocations[DockTypes.BottomLeft]) { dockPointLocations[DockTypes.BottomLeft] = AddHeightToDockPoint(DockTypes.BottomLeft, -controlCopy.Height); } if (controlBeingAdded.DockPointLocation == dockPointLocations[DockTypes.Top]) { dockPointLocations[DockTypes.Top] = AddWidthToDockPoint(DockTypes.Top, controlCopy.Width); } if (controlBeingAdded.DockPointLocation == dockPointLocations[DockTypes.Bottom]) { dockPointLocations[DockTypes.Bottom] = AddWidthToDockPoint(DockTypes.Bottom, controlCopy.Width); } if (controlBeingAdded.DockPointLocation == dockPointLocations[DockTypes.TopRight]) { dockPointLocations[DockTypes.TopRight] = AddHeightToDockPoint(DockTypes.TopRight, controlCopy.Height); } if (controlBeingAdded.DockPointLocation == dockPointLocations[DockTypes.Right]) { dockPointLocations[DockTypes.Right] = AddHeightToDockPoint(DockTypes.Right, controlCopy.Height); } if (controlBeingAdded.DockPointLocation == dockPointLocations[DockTypes.BottomRight]) { dockPointLocations[DockTypes.BottomRight] = AddHeightToDockPoint(DockTypes.BottomRight, -controlCopy.Height); } if (controlBeingAdded.DockPointLocation == dockPointLocations[DockTypes.Top2]) { dockPointLocations[DockTypes.Top2] = AddWidthToDockPoint(DockTypes.Top2, -controlCopy.Width); } if (controlBeingAdded.DockPointLocation == dockPointLocations[DockTypes.Bottom2]) { dockPointLocations[DockTypes.Bottom2] = AddWidthToDockPoint(DockTypes.Bottom2, -controlCopy.Width); } break; } } }