/// <summary> /// Called after the control has been added to another container. /// </summary> /// <remarks>Adds the TOPLEFT anchor</remarks> protected override void InitLayout() { base.InitLayout(); // set ControlFactory ISerializableControl serializableParent = this.Parent as ISerializableControl; if (serializableParent == null) { return; } this.DesignerLoader = serializableParent.DesignerLoader; if (this.SuspendLayouting) { return; } if (this.LayoutFrameType.SizeDimension == null) { this.LayoutFrameType.SizeDimension = Dimension.FromSize <Dimension.Size>(this.Size); } LayoutFrameTypeAnchors anchors; if (this.LayoutFrameType.AnchorsCollection.Count == 0) { anchors = new LayoutFrameTypeAnchors(); this.LayoutFrameType.AnchorsCollection.Add(anchors); } else { anchors = this.LayoutFrameType.AnchorsCollection[0]; } if (anchors.Anchor.Count == 0) { LayoutFrameTypeAnchorsAnchor anchor = new LayoutFrameTypeAnchorsAnchor(); anchor.point = FRAMEPOINT.TOPLEFT; anchor.Offset = new Dimension(); anchor.Offset.Update(this.Left, this.Top); anchors.Anchor.Add(anchor); this.DoChangeLayout(); } }
/// <summary> /// Updates the control anchor. /// </summary> /// <param name="controlAnchor">The control anchor to be updated.</param> /// <param name="control">The control.</param> /// <param name="anchor">The anchor.</param> private void SetControlAnchor(LayoutFrameTypeAnchorsAnchor anchor, bool inherited) { Point anchorPoint = anchor.GetRelativePoint(this.Parent); if (anchor.Offset != null) { Size offset = anchor.Offset.GetSize(); // Height is substracted because MultiverseInterface y coordinate increases upwards anchorPoint.Offset(offset.Width, -offset.Height); } string pointText = anchor.point.ToStringValue(); ControlAnchors.SideAnchor sideAnchor = new ControlAnchors.SideAnchor() { Anchor = anchor, Offset = anchorPoint, Inherited = inherited }; if (pointText.StartsWith("TOP")) { this.ControlAnchors.Top = sideAnchor; } if (pointText.StartsWith("BOTTOM")) { this.ControlAnchors.Bottom = sideAnchor; } if (pointText.EndsWith("LEFT")) { this.ControlAnchors.Left = sideAnchor; } if (pointText.EndsWith("RIGHT")) { this.ControlAnchors.Right = sideAnchor; } if (anchor.point == FRAMEPOINT.CENTER) { this.ControlAnchors.Center = sideAnchor; } }