Articles in this section

How can I progammatically add a symbol from the palette?

How can I programmatically add a symbol from the palette?

The following code sample demonstrates how you can programmatically add a symbol from the symbol palette to a Diagram.

[C#]

//New InsertNodesCmd InsertNodesCmd insCmd = new InsertNodesCmd();
// Select the Symbol from the PaletteGroupView
this.paletteGroupView1.SelectSymbolModel(this.paletteGroupView1.GroupViewItems[1].Text);
SymbolModel symModel = this.paletteGroupView1.SelectedSymbolModel;
// New NodeCollection
NodeCollection nodes = new NodeCollection();
// Add Symbol to the NodeCollection
if (symModel != null)
{
    Symbol triangle = symModel.CreateSymbol();
    nodes.Add(triangle);
}
insCmd.Nodes.Concat(nodes);
insCmd.Location = new PointF(125, 125);
// ExecuteCommand to add the Symbol
this.diagram1.Controller.ExecuteCommand(insCmd);

 

 [VB.NET]  

' New InsertNodesCmd
Dim insCmd As New InsertNodesCmd()
' Select the Triangle from the PaletteGroupView
Me.paletteGroupView1.SelectSymbolModel(Me.paletteGroupView1.GroupViewItems(1).Text)
Dim symModel As SymbolModel = Me.paletteGroupView1.SelectedSymbolModel
' New NodeCollection
Dim nodes As New NodeCollection()
' Add Symbol to the NodeCollection
If Not (symModel Is Nothing) Then
    Dim triangle As Symbol = symModel.CreateSymbol()
    nodes.Add(triangle)
End If
insCmd.Nodes.Concat(nodes)
insCmd.Location = New PointF(125, 125)
' Execute the InsertNodesCmd
Me.diagram1.Controller.ExecuteCommand(insCmd)

 

Conclusion

I hope you enjoyed learning about how can I progammatically add a symbol from the palette.

You can refer to our 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)
Access denied
Access denied