How To Create a Custom Symbol
29 Feb 2016 / 5 minutes to read
The following code sample demonstrates how you can create a custom symbol and use it in Essential Diagram.
-
Create the custom symbol.
// Custom Symbol (MySymbol.cs) public class MySymbol : Symbol { private Syncfusion.Windows.Forms.Diagram.Rectangle outerRect = null; private Ellipse innerEllipse = null; public MySymbol() { // Add child nodes to the symbol programmatically. // Add an outer rectangle. this.outerRect = new Syncfusion.Windows.Forms.Diagram.Rectangle(0, 0, 120, 80); this.outerRect.Name = "Rectangle"; this.outerRect.FillStyle.Color = Color.Khaki; this.AppendChild(outerRect); // Add an inner ellipse. this.innerEllipse = new Ellipse(10, 10, 100, 60); this.innerEllipse.Name = "Ellipse"; this.AppendChild(innerEllipse); // Add Label. Label lbl = this.AddLabel("My Symbol", BoxPosition.Center); lbl.BackgroundStyle.Color = Color.Transparent; } }
' Custom Symbol (MySymbol.vb) Public Class MySymbol Inherits Symbol Private outerRect As Syncfusion.Windows.Forms.Diagram.Rectangle = Nothing Private innerEllipse As Syncfusion.Windows.Forms.Diagram.Ellipse = Nothing Public Sub New() ' Add child nodes to the symbol programmatically. ' Add an outer rectangle. Me.outerRect = New Syncfusion.Windows.Forms.Diagram.Rectangle(0, 0, 120, 80) Me.outerRect.Name = "Rectangle" Me.outerRect.FillStyle.Color = Color.Khaki Me.AppendChild(outerRect) ' Add an inner ellipse. Me.innerEllipse = New Syncfusion.Windows.Forms.Diagram.Ellipse(10, 10, 100, 60) Me.innerEllipse.Name = "Ellipse" Me.AppendChild(innerEllipse) ' Add Label. Dim lbl As Label = Me.AddLabel("My Symbol", BoxPosition.Center) lbl.BackgroundStyle.Color = Color.Transparent End Sub ' New End Class ' MySymbol
-
Use the symbol in the form.
// Register InsertTool for MySymbol. this.diagram1.Controller.RegisterTool(new InsertSymbolTool("InsertMySymbol", typeof(MySymbol))); // Activate InsertTool for MySymbol. this.diagram1.ActivateTool("InsertMySymbol");
' Register InsertTool for MySymbol. Me.diagram1.Controller.RegisterTool(New InsertSymbolTool("InsertMySymbol", GetType(MySymbol))) ' Activate InsertTool for MySymbol. Me.diagram1.ActivateTool("InsertMySymbol")
Was this page helpful?
Yes
No
Thank you for your feedback!
Thank you for your feedback and comments. We will rectify this as soon as possible!
An unknown error has occurred. Please try again.
Help us improve this page