Articles in this section
Category / Section

How do I determine when a new symbol or shape has been added to or removed from the Diagram?

3 mins read

How do I determine when a new symbol or shape has been added to or removed from the Diagram?

The Diagram.Model.ChildrenChangeComplete event can be used to determine when a new node (symbol, shape, or link) has been added or removed from the diagram. The event's Diagram.NodeCollection.EventArgs event argument provides information about the node and the ensuing operation, such as addition or removal.

The following code sample updates the label with information on the type of node that is added to or deleted from the Diagram:

[C#]

// Listen to the Diagram Model's ChildrenChangeComplete Event.
this.diagram1.Model.ChildrenChangeComplete += new Syncfusion.Windows.Forms.Diagram.NodeCollection.EventHandler(Model_ChildrenChangeComplete);
// ChildrenChangeComplete Event
// Update Label2 depending on whether a Shape is added or deleted from the Diagram
private void Model_ChildrenChangeComplete(object sender, Syncfusion.Windows.Forms.Diagram.NodeCollection.EventArgs evtArgs)
{
    if (evtArgs.ChangeType.ToString() == "Insert")
    {
        this.label2.ForeColor = Color.Blue;
        this.label2.Text = "Last Node Added: " + evtArgs.Node.Name.ToString();
    }
    else if (evtArgs.ChangeType.ToString() == "Remove")
    {
        this.label2.ForeColor = Color.Red;
        this.label2.Text = "Last Node Removed: " + evtArgs.Node.Name.ToString();
    }
}

[VB.NET]

' Listen to the Diagram Model's ChildrenChangeComplete Event.
Me.diagram1.Model.ChildrenChangeComplete += New Syncfusion.Windows.Forms.Diagram.NodeCollection.EventHandler(Model_ChildrenChangeComplete)

' ChildrenChangeComplete Event
' Update Label2 depending on whether a Shape is added or deleted from the Diagram
Private Sub Model_ChildrenChangeComplete(ByVal sender As Object, ByVal evtArgs As Syncfusion.Windows.Forms.Diagram.NodeCollection.EventArgs)
    If evtArgs.ChangeType.ToString() = "Insert" Then
        Me.label2.ForeColor = Color.Blue
        Me.label2.Text = "Last Node Added: " + evtArgs.Node.Name.ToString()
    ElseIf evtArgs.ChangeType.ToString() = "Remove" Then
        Me.label2.ForeColor = Color.Red
        Me.label2.Text = "Last Node Removed: " + evtArgs.Node.Name.ToString()
    End If
End Sub

 

Conclusion

I hope you enjoyed learning about how to determine when a new symbol or shape has been added to or removed from the Diagram.

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 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