GoPort Bounds updating GoTextNode

I’ve got a few subclasses of things, but am having a basic problem which is this:

My GoTextNode has a Port. The size of which is set to the size of the Node (basically making the whole thing draggable). When the GoTextNode.Bounds change, the Port dimensions need to resize to match.

However, what I’m finding is I get a StackOverflow. It appears that changing the Bounds on the Port, Changes the Bounds on the node, which changes the Bounds on the Port again… I’ve got autoresizes/autorescale etc all turned off, and can’t figure out why this is happening.

Can anyone make any suggestions on how to avoid this recursion?

Thanks

Can you email your GoTextNode class to “godiagram” at this forum’s domain?

It’s a bit tricky to email over as there are a number of inter dependencies, the bit that is causing me the problem:

public override RectangleF Bounds
{
get
{
return base.Bounds;
}
set
{
RectangleF origBounds = this.Bounds;
base.Bounds = value;
SizeF moveVector = new SizeF(this.Position) - new SizeF(origBounds.Location);
SizeF widthResizeVector = new SizeF(this.Width - origBounds.Width, 0);
//Anchored top-right.
Translate(moveVector + widthResizeVector, this.errorFrame);
Translate(moveVector + widthResizeVector, this.tempErrorFrame);

            if(LeftPort != null)
                  LeftPort.Bounds = value;
            if(RightPort != null)
                   RightPort.Bounds = value;
        }
    }

then on a Sub class:

public override RectangleF Bounds
{
get { return base.Bounds; }
set
{
SizeF origLoc = new SizeF(this.Position);
base.Bounds = value;
SizeF moveVector = new SizeF(this.Position) - origLoc;
//this.title.Position += moveVector;
if (this.Relationships != null)
{
this.Relationships.ForEach(r => r.Position += moveVector);
}
if (this.toggleArrow != null)
{
this.toggleArrow.Location += moveVector;
}
if (this.relationshipImage != null)
{
this.relationshipImage.Location += moveVector;
}

           GoHeadingText label = this.Label as GoHeadingText;
            if (label != null)
            {
                if (label.SetLabelBounds == false)
                {
                    float x = this.Bounds.Left;
                    float y = this.Bounds.Top + this.TopLeftMargin.Height;
                    float width = this.Bounds.Width - this.TopLeftMargin.Width;
                    float height = MinHeight - this.TopLeftMargin.Height;
                    RectangleF newBounds = new RectangleF(x, y, width, height);

                    if (this.LeftPort != null)
                    {
                        this.LeftPort.Bounds = newBounds;
                    }
                    if (this.RightPort != null)
                    {
                        this.RightPort.Bounds = newBounds;
                    }

                    newBounds.X += this.TopLeftMargin.Width;

                    label.SetBounds(newBounds);                       
                }
            }
    }

}

You shouldn’t be overriding the Bounds setter to modify other objects – I bet that’s what’s causing the undesired recursion.

Instead, override the node’s LayoutChildren method to do what you want. I suggest you look at some of the example classes first.

Would you be able to email me some examples over? I’m using the 2.6.1 version of Express and I don’t believe there are any example implementations of LayoutChildren in them?

Flowcharter.Graphnode is the only one.

You could download the full GoDiagram kit and use the full list of samples as a reference… just realize there are going to be things there you can’t use in Express.