Articles in this section
Category / Section

How do I create a connection programmatically?

2 mins read

How do I create a connection programmatically?

Typically, symbols and links are connected together using the interactive LinkTool UI tool or the LinkCmd command class. Sometimes it is useful to create connections programmatically. For example, you might be generating a diagram from data in a database or possibly even writing your own custom link tool. You might even create a connection between two symbols directly without having a link in between.

The following code creates a link and connects it to the center ports of two symbols:

[C#]

public Link LinkSymbols(Symbol sym1, Symbol sym2) {     
Link link = new Link(Link.Shapes.Line);    
sym1.Connect(sym1.CenterPort, link.TailPort);     
sym2.Connect(link.HeadPort, sym2.CenterPort);    
 return link; }

[VB.NET]

Public Function LinkSymbols(ByVal sym1 As Symbol, ByVal sym2 As Symbol) As Link    
 Dim link As Link =  New Link(Link.Shapes.Line)    
 sym1.Connect(sym1.CenterPort, link.TailPort)    
 sym2.Connect(link.HeadPort, sym2.CenterPort)     
Return link End Function

 

Conclusion

I hope you enjoyed learning about how to create a connection programmatically.

You can refer to 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 forumsDirect-Trac, or feedback portal. We are always happy to assist you!

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