Resize an object and have the text move


I have a case where I have say a GoRectangle with a GoText in it the Rectangle is sized so that the text inside it will fit nice in the middlecenter but if you resize the rectangle the text stay where it is…
I dont want the text to resize but I certainly do want the text to move to a new center… how can I do this… is it doable?


Basically how do I change the location of anything programmatically after it has been set? Like on mouse over object.left = myLeft++; or something…


Programmatically you can just do something like:
obj.Left += 7;
You can certainly do that in a GoView event handler, or in a GoObject “event handler” (an override of one of the On… methods).
For groups, when you need to control the sizes and positions of the children, you should override GoGroup.LayoutChildren. There are a bunch of examples in the sample apps.
The standard behavior when resizing a group is to resize and reposition the children proportionately. This is implemented by GoGroup.ResizeChildren, which rarely needs to be overridden.
The standard behavior when a child is moved or resized is to do nothing additional. This is why most of the node classes override LayoutChildren.
For example, GoBasicNode overrides LayoutChildren so that when the LabelSpot is Middle and the size of the Label (a GoText object) changes, presumably because its Text string changed, it changes the Position and Size of the Shape object (by default a GoEllipse object) to surround the text Label.
But if you set GoBasicNode.AutoResizes to false, then it is the Shape that determines the Position and Size of the Label, to make sure the Label fits inside the Shape. This is just a different behavior that LayoutChildren takes, depending on the properties of the class.


See now I have tried everything you said there but none really works for me in this case… The text always stays where it was initially created…


Well, either it is part of a GoGroup whose LayoutChildren is preventing the text object from moving, or the GoText’s Bounds setter has been overridden to disallow moving the object.
To state it more precisely in the first case, the object is moving, but LayoutChildren is moving it back.


I have boxes that inherit GoTextNode and basically follow the pattern for the FixedTextNode that is in the sample application. With this inheritance you can then do the following override in code: (BTW: This board could use a tag so that our code is all single-spaced) This code handles the resize of text as the object is scaled. In really large diagrams it scales down to little itty-bitty lines. I use ToolTipText to let a mouse hover show what the value is.

public override void LayoutChildren(GoObject childchanged)
GoObject bg = this.Background;
if (bg != null)
GoText lbl = this.Label;
if (lbl != null)
SizeF tlMargin = this.TopLeftMargin;
SizeF brMargin = this.BottomRightMargin;
// compute label bounds from background bounds
// plus the top left and bottom right margins.
float maxLblWidth = Math.Max(bg.Width - (tlMargin.Width + brMargin.Width), 0);
float maxLblHeight = Math.Max(bg.Height - (tlMargin.Height + brMargin.Height), 0);
float lblHeight = Math.Min(lbl.Height, maxLblHeight);
float lblLeft = bg.Left + tlMargin.Width;
float lblTop = bg.Top + tlMargin.Height + (maxLblHeight-lblHeight)/2;
lbl.Bounds = new RectangleF(lblLeft, lblTop, maxLblWidth, lblHeight);
lbl.WrappingWidth = maxLblWidth;

// set position of all ports

if (this.TopPort != null)
this.TopPort.SetSpotLocation(MiddleTop, bg, MiddleTop);
if (this.RightPort != null)
this.RightPort.SetSpotLocation(MiddleRight, bg, MiddleRight);
if (this.BottomPort != null)
this.BottomPort.SetSpotLocation(MiddleBottom, bg, MiddleBottom);
if (this.LeftPort != null)
this.LeftPort.SetSpotLocation(MiddleLeft, bg, MiddleLeft);