A question on GoBasicNode

All of my GoBasicNodes are of the same size. When the mouse pointer is over the area around the node’s label, it changes into a hand and I can drag to create a link. How do I control this area to be as narrowed as a few points from the edges?

Thanks,
Henry

Everything that isn’t “Label” is port for starting a link.



You can steal the logic from HollowRectangle in SwimLane (from NodeLinkDemo) and apply it to a GoPort, like this:



[Serializable]

public class BigCenterBasicNode : GoBasicNode {



protected override GoPort CreatePort() {

// create a Port, which knows how to make sure

// connected GoLinks have a reasonable end point

GoPort p = new HollowPort();

p.Style = GoPortStyle.Ellipse; // black circle/ellipse

// use custom link spots for both links coming in and going out

p.FromSpot = GoObject.NoSpot;

p.ToSpot = GoObject.NoSpot;

p.Size = new SizeF(7, 7);

return p;

}

}



[Serializable]

public class HollowPort : GoPort {



public override bool ContainsPoint(PointF p) {

RectangleF r = this.Bounds;

r.Inflate(-this.PickMargin, -this.PickMargin);

if (r.Contains§) return false;

return base.ContainsPoint§;

}



public float PickMargin {

get { return myPickMargin; }

set {

float old = myPickMargin;

if (old != value) {

myPickMargin = value;

Changed(ChangedPickMargin, 0, null, MakeRect(old), 0, null, MakeRect(value));

}

}

}



public override void ChangeValue(GoChangedEventArgs e, bool undo) {

switch (e.SubHint) {

case ChangedBounds:

base.ChangeValue(e, undo);

break;

case ChangedPickMargin: this.PickMargin = e.GetFloat(undo); break;

default: base.ChangeValue(e, undo); break;

}

}



public const int ChangedPickMargin = GoDocument.LastHint + 414;



private float myPickMargin = 5;



}

Thanks Jake. Your solution works great!

Henry