Changing link appearance wrt port data


I would like to change the appearance of a link depending on some data available in the from port of this link.

I beleive my entry point to do so is to derive from GoLink, overload OnPortChanged so that I can read the information, and set the pen accordingly.

However, when I tried:

public override void OnPortChanged(IGoPort port, int subhint, int oldI, object oldVal, System.Drawing.RectangleF oldRect, int newI, object newVal, System.Drawing.RectangleF newRect) { base.OnPortChanged(port, subhint, oldI, oldVal, oldRect, newI, newVal, newRect); // Get some port information MyPortData a = (FromPort as MyPort).Data; //....

I go a message ‘FromPort’ threw an exception of type ‘System.ArgumentNullException’.

I guess that during this call, the from port is still not set correctly, and I may get some information about it in the undocumented parameters of this function.

Am I in the good direction ? What should I do ?

Best regards,

PS : I could have some result with overloading GoView.CreateLink, but in that case, the new style is applied only when the mouse button is released, not while the link in creation is being dragged. I’m not sure the method with OnPortChanged would work either…

No, handling the low level changes for ports of a link probably isn’t what you want to do. It’s a lot easier to do what I guess you first started to do with the override of GoView.CreateLink, but as you found out, it didn’t affect the drawing-a-new-link process.
The way to do that is to override a method in GoToolLinkingNew and use that as a replacement for the standard linking tool. As a benefit, you can also implement the code you were going to put into GoView.CreateLink in this custom tool, since GoToolLinkingNew.DoNewLink just calls GoView.CreateLink.
Something like the following code, which (assuming your GoView creates new GoLabeledLinks) makes a GoLabeledLink.MidLabel whose Text value is the same as the Text of the Node of the FromPort.
public class TestLinkingNewTool : GoToolLinkingNew {
public TestLinkingNewTool(GoView view) : base(view) {}
protected override IGoLink CreateTemporaryLink(IGoPort fromPort, IGoPort toPort) {
IGoLink result = base.CreateTemporaryLink(fromPort, toPort);
InitAccordingToPort(result, this.OriginalStartPort);
return result;
public override void DoNewLink(IGoPort fromPort, IGoPort toPort) {
IGoLink link = this.View.CreateLink(fromPort, toPort);
if (link != null) {
InitAccordingToPort(link, fromPort);
this.TransactionResult = GoUndoManager.NewLinkName;
} else {
this.TransactionResult = null;
public GoLabeledLink InitAccordingToPort(IGoLink link, IGoPort port) {
GoLabeledLink ll = link as GoLabeledLink;
if (ll != null && port != null && port.Node is IGoLabeledPart) {
GoText t = new GoText();
t.Selectable = false;
t.Text = ((IGoLabeledPart)port.Node).Text;
ll.MidLabel = t;
return ll;
return null;
Replace the standard tool with this one by:
goView1.ReplaceMouseTool(typeof(GoToolLinkingNew), new TestLinkingNewTool(goView1));

Thank you for your help, after customizing the GoToolRelinking too, it works as intended.