Ports move after editing label text

I’ve created a node that inherits from GoGeneralNode and is based on the InfoNode8 and SequencedNode classes of the Demo.

Whenever the top label changes (either programmatically or via user edits), the top and bottom ports move to the sides of the node instead of remaining in the top and bottom of the node.
I've tried many variations in the way I set the nodes' spotPositions within the LayoutChildren method, but none seem to correct the problem.
Below is my LayoutChildren method. I appreciate any suggestions you have to help me fix this problem.
Tom

public override void LayoutChildren( GoObject childchanged )<?: prefix = o ns = "urn:schemas-microsoft-com:office:office" />

{

base.LayoutChildren( childchanged );

GoGroup icongrp = this.Icon as GoGroup;

if ( icongrp != null )

{

GoObject toplab = this.TopLabel;

GoObject botlab = this.BottomLabel;

if ( toplab != null && icongrp.Count > 0 )

{

toplab.Center = icongrp[ 0 ].Center;

}

if ( botlab != null && icongrp.Count > 1 )

{

botlab.Center = icongrp[ 1 ].Center;

}

if ( this.TopPort != null && icongrp.Count > 0 )

{

this.TopPort.SetSpotLocation( BottomCenter, this.TopLabel, MiddleTop );

}

if ( this.BottomPort != null && icongrp.Count > 1 )

{

this.BottomPort.SetSpotLocation( TopCenter, this.BottomLabel, MiddleBottom );

}

}

}

Is your “this.Icon” really a GoGroup? The base.LayoutChildren is going to move them to the sides if you are really using side ports and moving them to the top and bottom.

I’m new to this and so may not have used the best approach for creating the top and bottom ports.

Here are my Initialize and CreateIcon methods. My node inherits from GoGeneralNode.

public void Initialize()<?: prefix = o ns = "urn:schemas-microsoft-com:office:office" />

{

this.Resizable = false;

Initialize( null, @"star.gif", "New Criteria", "", 0, 0 );

this.LeftPortsAlignment = MiddleRight;

this.LeftPortLabelsInside = true;

this.LeftPortsLabelSpacing = 4;

this.RightPortsAlignment = MiddleLeft;

this.RightPortLabelsInside = true;

this.RightPortsLabelSpacing = 4;

//---------------------------------------------------------------------------

// Initialize label appearance

//---------------------------------------------------------------------------

this.TopLabel.Bold = true;

this.TopLabel.Editable = true;

this.TopLabel.FontSize = 8;

this.BottomLabel.Bold = true;

this.BottomLabel.Editable = false;

this.BottomLabel.FontSize = 8;

//---------------------------------------------------------------------------

// Add additional ports: one on the top, one on the bottom

//---------------------------------------------------------------------------

m_TopPort = CreatePort( true );

this.Add( this.TopPort );

m_BottomPort = CreatePort( false );

this.Add( this.BottomPort );

//---------------------------------------------------------------------------

// Temporary - Create Button

//---------------------------------------------------------------------------

GoButton but = new GoButton();

but.Selectable = false;

but.Text = "?";

but.TopLeftMargin = new SizeF( 0, 0 );

but.BottomRightMargin = new SizeF( 0, 0 );

Insert( 2, but ); // == this[2]

but.Action += new GoInputEventHandler( but_Action );

}

///

/// Generated the body (i.e. Icon) of the display node.

/// This consists of two rounded rectangles (top and bottom), each holding a label

///

///

///

///

protected override GoObject CreateIcon( System.Resources.ResourceManager res, string iconname )

{

// Top rectangle

GoRoundedRectangle r1 = new GoRoundedRectangle();

r1.Selectable = false;

r1.Size = new SizeF( 100, 20 );

r1.RoundedCornerSpots = TopLeft | TopRight;

r1.FillSimpleGradient( Color.Green, Color.PaleGreen, MiddleTop );

// Bottom rectangle

GoRoundedRectangle r3 = new GoRoundedRectangle();

r3.Selectable = false;

r3.Size = new SizeF( 100, 20 );

r3.RoundedCornerSpots = BottomLeft | BottomRight;

r3.FillSimpleGradient( Color.PaleGreen, Color.Green, MiddleTop );

// Container

GoListGroup list = new GoListGroup();

list.Selectable = false;

list.AutoRescales = false;

list.TopLeftMargin = new SizeF( 0, 0 );

list.BottomRightMargin = new SizeF( 0, 0 );

list.Add( r1 );

list.Add( r3 );

return list;

}

OK… I don’t see anything obvious in the code you’ve provided, but I’m going to take a wild guess.

You’re creating these nodes by dragging and dropping from a palette (thus they are being copied) and you don’t have a CopyChildren method to set m_TopPort and m_BottomPort correctly.

Go back to the SequencedNode sample I pointed you at earlier (it really is very similar to your requirements) and see what the method CopyChildren is doing.

…OR, if that wasn’t right…

just set a breakpoint in your LayoutChildren and then edit the label and see what happens when you step through the code.