LayoutChildren and Resizing

I have the following class:

public class StateMachineNode : StateNode
{
    GoRectangle r;
    public StateMachineNode()
    {
          r = new GoRectangle();
          r.Selectable = false;
          r.Movable = false;
          r.Resizable = false;
          r.ResizesRealtime = true;
          r.Brush = Brushes.WhiteSmoke;
          r.Pen = Pens.Black;
          this.Size = new SizeF(50, 50);
          r.Size = new SizeF(40, 40);

          this.InsertBefore(this.Label,r);
    }

    public override void LayoutChildren(GoObject childchanged)
    {              
          base.LayoutChildren(childchanged);
          //if (this.Initializing) return;
          GoObject back = this.Background;
          if (back != null && r != null)
          {
              r.Bounds = new RectangleF(back.Left + 5, back.Top + 5, back.Width - 10, back.Height - 10);
          }
    }
}

It displays correctly when I add it to a goView. However when I change the text on the Label the inner box is not repositioned correctly. Is there another function I should override to take care of this?

Regards,

Martin

Have you made a copy of your node? If so, the field “r” is still referring to the original’s GoRectangle, not the copied node’s GoRectangle. You should override CopyChildren:
protected override void CopyChildren(GoGroup newgroup, GoCopyDictionary env) {
base.CopyChildren(newgroup, env);
StateMachineNode newobj = (StateMachineNode)newgroup;
newobj.r = (GoRectangle)env[r];
}

Thanks Walter, that was it. For some reason I thought that the CopyChildren would make a copy of any GoObjects. Now to change my other ‘working’ shapes :-)

Regards,

Martin

To clarify: GoGroup.CopyChildren does make copies of all child GoObjects. That’s why you have to call the base method.
It’s just that since you have added a field referring to a child object, you almost certainly want to refer to the child in your group, not to some child in a differerent group.