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
Else
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 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.
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.
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.
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.
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
C#
public GoPort LeftSidePort {
get { return myLeftPort; }
}
public GoPort RightSidePort {
get { return myRightPort; }
}
VB:
Public ReadOnly Property LeftSidePort() As GoPort
Get
Return myLeftPort
End Get
End Property
Public ReadOnly Property RightSidePort() As GoPort
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