Articles in this section
Category / Section

How to draw links between two node or how to connect two nodes with a line connector programmatically?

1 min read

How to draw links between two node or how to connect two nodes with a line connector programmatically?

The following code is demonstrated in Symbol Design\Dynamic Symbol class.

C#

NodeCollection symbols = new NodeCollection();
 // Add nodes of custom symbol type.
MySymbol symbol1 = new MySymbol();
symbol1.PinPoint = new PointF(10 + symbol1.PinPointOffset.Width, 10 + symbol1.PinPointOffset.Height);
symbol1.EnableCentralPort = true;
symbols.Add(symbol1);
 MySymbol symbol2 = new MySymbol();
symbol2.PinPoint = new PointF(200, 200);
symbol2.EnableCentralPort = true;
symbols.Add(symbol2);
 int position = 0;
 // Draw the Lineconnector and add it to the nodes collection.
LineConnector line = new LineConnector(symbol1.PinPoint, symbol2.PinPoint);
symbols.Add(line);
 // Add the nodes collection that has nodes and the connectors to the diagram model.
this.diagram1.Model.AppendChildren(symbols, out position);
 // Make connection between the two nodes and the line connector through its end point.
symbol1.CentralPort.TryConnect(line.HeadEndPoint);
symbol2.CentralPort.TryConnect(line.TailEndPoint);
 

 

VB

Private symbols As NodeCollection = New NodeCollection()
 '' Add nodes of custom symbol type.
Private symbol1 As MySymbol = New MySymbol()
symbol1.PinPoint = New PointF(10 + symbol1.PinPointOffset.Width, 10 + symbol1.PinPointOffset.Height)
symbol1.EnableCentralPort = True
symbols.Add(symbol1)
 Private symbol2 As MySymbol = New MySymbol()
symbol2.PinPoint = New PointF(200, 200)
symbol2.EnableCentralPort = True
symbols.Add(symbol2)
 Private position As Integer = 0
 '' Draw the Lineconnector and add it to the nodes collection.
Private line As LineConnector = New LineConnector(symbol1.PinPoint, symbol2.PinPoint)
symbols.Add(line)
 '' Add the nodes collection that has nodes and the connectors to the diagram model.
Me.diagram1.Model.AppendChildren(symbols, position)
 '' Make connection between the two nodes and the line connector through its end point.
symbol1.CentralPort.TryConnect(line.HeadEndPoint)
symbol2.CentralPort.TryConnect(line.TailEndPoint)
 

 

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please sign in to leave a comment
Access denied
Access denied