/// <summary> /// Replaces this container from the parent with a different container /// </summary> /// <param name="container">container that replaces this container</param> public void ReplaceWith(BaseContainer container) { if (ParentContainer != null) { ParentContainer.ReplaceChild(this, container); } }
/// <summary> /// Removes a child from this container /// </summary> /// <param name="container">Container to remove</param> public virtual void RemoveChild(BaseContainer container) { container.ParentContainer = null; Children.Remove(container); Controls.Remove(container); OnRemove?.Invoke(container); }
/// <summary> /// Moves the selected container to the container that is below the mouse (ignoreing the selected container) /// </summary> public void MoveSelectedToBelow() { if (SelectedContainer != null) { // get the new container of the selected container BaseContainer newContainer = FindContainerAtPoint(MousePosition, SelectedContainer); if (newContainer is PlaceHolder) { newContainer = newContainer.ParentContainer; if (newContainer is Container) { Container container = (Container)newContainer; if (container.RenderMode == ContainerRenderMode.Linear) { RemoveChild(SelectedContainer); PlaceHolder.ReplaceWith(SelectedContainer); SelectedContainer.Location = PlaceHolder.Location; RemovePlaceHolder(); return; } } } // update the location of the selected Point selectedScreen = SelectedContainer.PointToScreen(Point.Empty); Point difference = newContainer.PointToClient(selectedScreen); SelectedContainer.Location = difference; // move to new SelectedContainer.MoveTo(newContainer); RemovePlaceHolder(); } }
/// <summary> /// Adds a child to this container /// </summary> /// <param name="container">Container</param> public virtual void AddChild(BaseContainer container) { container.ParentContainer = this; Children.Add(container); Controls.Add(container); container.BringToFront(); OnAdd?.Invoke(container); }
/// <summary> /// Move this container to a new parent /// </summary> /// <param name="newParent">new parent</param> public void MoveTo(BaseContainer newParent) { if (ParentContainer != null) { ParentContainer.RemoveChild(this); } newParent.AddChild(this); }
/// <summary> /// Replaces a child (if exists) from children with another child /// </summary> /// <param name="child">child to replace</param> /// <param name="newchild">new container that replaces the child</param> public void ReplaceChild(BaseContainer child, BaseContainer newchild) { if (Children.Contains(child)) { int controlindex = Controls.GetChildIndex(child); int childindex = Children.IndexOf(child); Children[childindex] = newchild; newchild.ParentContainer = this; Controls.Add(newchild); Controls.SetChildIndex(newchild, controlindex); Controls.Remove(child); OnAdd?.Invoke(newchild); } }
/// <summary> /// Finds the top-most container at the point specified /// </summary> /// <param name="pos">position in screen coordinates</param> /// <param name="ignore">a container that it will ignore even if it is the topmost and under the point</param> /// <returns>The container that is the top most and contains the point</returns> public virtual BaseContainer FindContainerAtPoint(Point pos, BaseContainer ignore = null) { BaseContainer mouse = this; // check if children contain the point foreach (BaseContainer child in Children) { // if the child contains the position and is not ignored if (child.ContainsPos(pos) && child != ignore) { // find the container in the child return(child.FindContainerAtPoint(pos, ignore)); } } return(mouse); }
/// <summary> /// Loads the values for this from xml /// </summary> /// <param name="xml">xml element</param> public virtual void LoadFromXML(XElement xml) { if (xml.Name != GetType().Name) { throw new InvalidXMLException("element name does not equal: " + GetType().Name, xml); } if (xml.HasElements) { IEnumerable <XElement> elements = xml.Elements(); foreach (XElement child in elements) { BaseContainer container = new BaseContainer(); AddChild(container); } } }
public void ChildToLinear(BaseContainer child) { child.Dock = DockStyle.Top; }