How do I enable the single link between the nodes?
In WinForms Diagram, we can eliminate creating two links for the same
two symbols by checking the link nodes FromNode, ToNode properties. While
creating lines we have to check the end points, if its end points is already
exists with the symbols then we have to remove the link. While creating links
we can get the link endpoints using ConnectionsChanged event.
C#
//Adding ConnectionChanged event ((DocumentEventSink)model1.EventSink).ConnectionsChanged += new CollectionExEventHandler(MainForm_ConnectionsChanged); //Event void MainForm_ConnectionsChanged(CollectionExEventArgs evtArgs) { if (evtArgs.ChangeType == CollectionExChangeType.Insert) { foreach (Node n1 in this.diagram1.Model.Nodes) { Line tl = n1 as Line; if (n1 is Line) { Line lc1 = n1 as Line; foreach (Node n in this.diagram1.Model.Nodes) { if (n is Line && n != n1) { Line lc = n as Line; if (((lc1.FromNode == lc.FromNode) && (lc1.ToNode == lc.ToNode)) || ((lc1.ToNode == lc.FromNode) && (lc1.FromNode == lc.ToNode))) { this.diagram1.Model.RemoveChild(lc1); MessageBox.Show("Aleardy link has created for the Symbols"); } } } } } } }
VB
'Adding ConnectionChanged event AddHandler (CType(model1.EventSink, DocumentEventSink)).ConnectionsChanged, AddressOf MainForm_ConnectionsChanged 'Event void MainForm_ConnectionsChanged(CollectionExEventArgs evtArgs) If evtArgs.ChangeType = CollectionExChangeType.Insert Then For Each n1 As Node In Me.diagram1.Model.Nodes Dim tl As Line = TryCast(n1, Line) If TypeOf n1 Is Line Then Dim lc1 As Line = TryCast(n1, Line) For Each n As Node In Me.diagram1.Model.Nodes If TypeOf n Is Line AndAlso Not n Is n1 Then Dim lc As Line = TryCast(n, Line) If ((lc1.FromNode = lc.FromNode) AndAlso (lc1.ToNode = lc.ToNode)) OrElse ((lc1.ToNode = lc.FromNode) AndAlso (lc1.FromNode = lc.ToNode)) Then Me.diagram1.Model.RemoveChild(lc1) MessageBox.Show("Aleardy link has created for the Symbols") End If End If Next n End If Next n1 End If
Conclusion
I hope you enjoyed learning about how to enable the single link between the nodes.
You can refer to our WinForms Diagram feature tour page to know about its other groundbreaking feature representations. You can also explore our WinForms Diagram documentation to understand how to present and manipulate data.
For current customers, you can check out our WinForms 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 WinForms Diagram and other WinForms components.
If you have any queries or require clarifications, please let us know in comments below. You can also contact us through our support forums, Direct-Trac, or feedback portal. We are always happy to assist you!