Postion of label inside GoBasicNode

HI!
I want to have a label inside a node inherited from GoBasicNode at the top in the middle. (The node is much bigger than the label) So I tried to set LabelSpot either to MiddleTop or TopCenter. In both cases the label is placed outside of the node. Is that the right behaviour? Is there any easy way - without calculating the appropriate position - to place the label there.
Thanks monika

Monica,

GoBasicNode gives you a simpler version of label positioning than what is possible.
If the labelSpot is not Middle... it does this in LayoutChildren
label.SetSpotLocation(SpotOpposite(this.LabelSpot), this.Shape, labelSpot);
so, if you specify MiddleTop (which is the same as TopCenter), you get it laid out relative to the SpotOpposite of the shape.
so, the MiddleTop of the shape and the MiddleBottom of the label are aligned.
Try this:
[Serializable]
public class TopLabelNode : GoBasicNode {
public TopLabelNode() {
this.Text = "Node 23";
this.LabelSpot = Middle;
this.AutoResizes = false;
this.Shape.Size = new SizeF(120, 60);
}
public override void LayoutChildren(GoObject childchanged) {
if (this.Initializing) return;
base.LayoutChildren(childchanged);
if (this.Label != null && this.Shape != null) {
PointF p = this.Shape.GetSpotLocation(MiddleTop);
p.Y += 5;
this.Label.SetSpotLocation(MiddleTop, p);
}
}
}

Hi,
Thanks that really helped to and to understand and solve the problem . But there is already a new problem:
I add a GoButton in a GoGroup. I try to place and set its size with the bounds of the button. But neither the size nor the place are where they ought to be. That is what I do:
GoButton button = new GoButton();
button.Bounds = new RectangleF(20, 20, 50, 20);
content_small.Add(button);
The group (content_small) is positioned in LayoutChildren of its parentnode. After trying to set the buttons bounds they are still (-3, -3, 15, 15). Any idea what I am doing wrong?
Monika

GoButton.LayoutChildren is defined to reshape the Background to surround the Icon and Label plus margins.
You could override GoButton.LayoutChildren to do something different, to allow you to size the button any way you want. That would require resizing the Icon and the Label so that they fit in the Background.

Ok, so it doesn’t make much sense to use GoButton.Bounds. But how can I place a button relative to the GoGroup to which it belongs?

That would be the responsibility of the parent group’s LayoutChildren method.

That means using GoButton.Bounds like in InfoNode makes only sense if the size of the label or icon is known and you can use the right size there?

I’m not sure what you mean. If you don’t want to change the behavior of GoButton.LayoutChildren, then you are accepting its current behavior which causes the size of the GoButton to be determined by the sizes of its Icon and its Label.
Certainly your group’s/node’s implementation of LayoutChildren can position the instance of GoButton whereever it wants to. Apparently the InfoNode example class didn’t bother to implement an override of LayoutChildren because it assumed that either none of the child objects would change size after the node was initialized, or that if any child did change size, it didn’t matter.