Can I create and new ports to a Symbol at runtime?
Can I create and new ports to a Symbol at runtime?
Essential® Diagram allows you to create new ports and add them to a symbol at runtime. Creating a new port is simply a matter of instantiating the required port, adding it to your symbol's Symbol.Ports collection, and specifying the port location. The following code should give you an idea:
The Diagram.Windows\Samples\Symbol Design\PortsAhoy sample that ships with the product demonstrates how to create and add new ports to a symbol.
C#
Symbol mysymbol; // Symbol reference // Center the port on the symbol PointF pt = new PointF(mysymbol.X + mysymbol.Width / 2, mysymbol.Y + mysymbol.Height / 2); CirclePort port = new CirclePort(pt); mysymbol.Ports.Add(port); port.Location = pt;
VB
Private mysymbol As Symbol ' Symbol reference ' Center the port on the symbol Private pt As PointF = New PointF(mysymbol.X + mysymbol.Width / 2, mysymbol.Y + mysymbol.Height / 2) Private port As CirclePort = New CirclePort(pt) mysymbol.Ports.Add(port) Private port.Location = pt
Conclusion
I hope you enjoyed learning about creating and adding new ports to a Symbol at runtime.
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!