How to draw links between two node or how to connect two nodes with a line connector programmatically?
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 points.
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)
Conclusion
I hope you enjoyed learning about how to draw links between two nodes or how to connect two nodes with a line connector programmatically.
You can refer to the WinForms Diagram feature tour page to learn about its other groundbreaking feature representations and documentation, and how to quickly get started for configuration specifications. You can also explore our WinForms Diagram example to understand how to create and manipulate data.
For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion®, you can try our 30-day free trial to check out our other controls.
If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forums, Direct-Trac, or feedback portal. We are always happy to assist you!