Ports Moving on Node

I have the following code to create a custom GoTextNode:

Imports System Imports System.Collections Imports System.ComponentModel Imports System.Diagnostics Imports System.Drawing Imports Northwoods.Go Public Class TestNode Inherits GoTextNode Private MyHeight As Single Private MyWidth As Single Public Shared myCounter As Integer = -1 Public Sub New() Me.Label.Editable = False Me.Resizable = False Me.UserFlags = -1 Me.Text = "Test O Rama" Dim rect As GoRoundedRectangle = New GoRoundedRectangle() MyWidth = 80 MyHeight = 100 Dim MyColor As New Color MyColor = Color.BurlyWood rect.Corner = New SizeF(Width / 2.5, MyWidth / 2.5) rect.FillSimpleGradient(Color.White, MyColor, GoObject.MiddleLeft) rect.PenColor = MyColor Me.Background = rect Me.TopLeftMargin = New SizeF((MyWidth - Me.Label.Width) / 2, MyHeight / 2) Me.BottomRightMargin = New SizeF((MyWidth - Me.Label.Width) / 2, MyHeight / 2) Me.TopPort = Nothing Me.BottomPort = Nothing Me.LeftPort = Nothing Me.RightPort = Nothing Dim MyPort As GoPort = New GoPort MyPort.Height = 10 MyPort.Width = 10 MyPort.Left = MyWidth / 2 + 5 MyPort.Top = -(MyHeight / 2) MyPort.Style = GoPortStyle.TriangleMiddleBottom MyPort.Brush = Brushes.LightBlue MyPort.IsValidTo = True MyPort.IsValidFrom = False MyPort.ToSpot = MiddleTop MyPort.EndSegmentLength = 15 Me.Add(MyPort) MyPort = New GoPort MyPort.Height = 10 MyPort.Width = 10 MyPort.Left = MyWidth / 2 - 15 MyPort.Top = -(MyHeight / 2) MyPort.Style = GoPortStyle.TriangleMiddleTop MyPort.Brush = Brushes.Blue MyPort.IsValidTo = False MyPort.IsValidFrom = True MyPort.FromSpot = MiddleTop MyPort.EndSegmentLength = 15 Me.Add(MyPort)

Me.Shadowed = True
Me.Movable = True
End Sub
Protected Overrides Sub OnLayerChanged(ByVal oldlayer As GoLayer, ByVal newlayer As GoLayer, ByVal mainObj As GoObject)
MyBase.OnLayerChanged(oldlayer, newlayer, mainObj)
’ don’t change the text when removing from a layer or when adding to a view layer
If (oldlayer Is Nothing AndAlso Not (newlayer Is Nothing) AndAlso newlayer.IsInDocument) Then
myCounter = myCounter + 1
If myCounter = 0 Then
Me.Text = “test”
Me.TopLeftMargin = New SizeF((MyWidth - Me.Label.Width) / 2, MyHeight / 2)
Me.BottomRightMargin = New SizeF((MyWidth - Me.Label.Width) / 2, MyHeight / 2)
End If
End If
End Sub

The problem I am having is that when I change the text the Ports are moving. What am I doing wrong?

It looks like you are trying to adjust the margin so that the overall width of the node stays the same as the text changes, right?

If I understand correctly, I don’t understand the line

Me.Text = “test”

it’s also not clear what’s going to happen if the Label.Width > MyWidth.

It may be that AutoResizes = false is what you’re looking for.

and the port positions are going to be reset every pass through LayoutChildren, so if you want to move ports out of their usual top/side/bottom spots, you’ll have to override LayoutChildren in a GoTextNode subclass.

The reason for the Me.text=“test” is in the program I am writting when a node is pulled from a GoPalette to a Goview I will increment the the text. For instance Test1, Test2, Test3 etc.

I am trying to keep the overall width the same when the text changes.

autoresizes=false didn’t help.

I am not sure what your second statement means. What I am after is a node that has the shape as shown in the code with 2 ports on the top one in one out. Two ports on the bottom on in one out and 1 port on each side with both in and out. I don't want the ports to move when I change the text.
Maybe I should be using something other than a GoTextNode.
I tried to look at the MultiPortNode example but unfortunately i can only look at the MultiPortNode Class and not the whole NodeLinkDemo so I am confused on how to use the MultiPortNode example.

Could you post a screenshot of what you’re looking for? I could build your code above, but I wouldn’t know if it was what you wanted for sure.

Use the “post reply” button with the icon at the bottom right of the page.

In the image below notice how the GoPorts move when I drag the Node from the GoPalette to the GoView.

Also I would like to keep the text to top of the nodes if possible.

One other quick note. I would like the Ports to appear and disappear when the Node is Selected and Loses Selection.

ok, thanks… this will help me generate a reply.

The red diamonds and blue triangles are all ports, right?

Input/Output pair on top and bottom, and the red ones are in on left and out on right?

Are the number of ports (and type of ports) going to changed based on node type?

Yes, I need an input-output pair at the top and bottom. I will need the red diamonds on the side to be input and outputs in one single port.

No the number of ports for this type of node will not change.

Jake - I will use three different types of the nodes. But they will each have the same ports. These pictures kind of show you how I will be using them. I hope this helps.

And here they are after they have been added to the view and linked up.

ok… code in

this zip file

in both c# and vb (although it was the C# I tested).

I did not add the disappearing ports, but you can copy similar logic from Flowcharter.

You were using GoGeneralNode, so I used that as a base. When GoGeneralNode.Orientation is Vertical, the “Left Ports” are on the top, and the “Right Ports” are on the bottom. This doesn’t generally cause too much confusion, except in this case there is also a LeftPort and RightPort.

oh… the width of this node varies with the label. After finishing and going back and looking at what you were doing, I’m pretty sure that’s wrong… but it should be easy to tweak.

Let me know if you have any questions or issues with the code.

Can you give me some code in VB how I would load this into my GoPalette? Apparently I am not getting it. That or some of the errors in the VB I corrected were wrong.

Never mind I got it. I have never had to intialize a node before but this one requires that.

What are the names of these ports?

For instance if I want to send a link to one of them:
Dim MyFanLink As GasLink = New GasLink MyFanLink.FromPort = TestNode.?

ah… the top 2 are GetLeftPort(0) and (1), the bottom 2 are GetRightPort(0) and (1). and they have names of Lnnn and Rnnn for FindName. (e.g. (FindName(“L0”)).

The ones on the side… I didn’t get you code for that, sorry.

Just add


public GoPort LeftSidePort {

get { return myLeftPort; }


public GoPort RightSidePort {

get { return myRightPort; }



Public ReadOnly Property LeftSidePort() As GoPort


Return myLeftPort

End Get

End Property

Public ReadOnly Property RightSidePort() As GoPort


Return myRightPort

End Get

End Property


To make it less confusing I add this as well:

Public ReadOnly Property BottomOutPort() As GoPort Get Return GetRightPort(1) End Get End Property Public ReadOnly Property BottomInPort() As GoPort Get Return GetRightPort(0) End Get End Property Public ReadOnly Property TopInPort() As GoPort Get Return GetLeftPort(1) End Get End Property Public ReadOnly Property TopOutPort() As GoPort Get Return GetLeftPort(0) End Get End Property