Create/Open the WinForms SubDiagram using NodeClick Events.
Create/Open the SubDiagram using NodeClick Events
We don’t have a built-in option to create/open a new subdiagram. However, we can achieve this requirement of opening the subdiagram at the application level. In this document, we are providing an example to create and open the subdiagram in another diagram’s model using WinForm Diagram’s NodeClick event.
The following code example for registering the NodeClick event to diagram’s controller
[C#]
// Registering the NodeClick event diagram1.EventSink.NodeClick += EventSink_NodeClick;
[VB]
' Registering the NodeClick event diagram1.EventSink.NodeClick += EventSink_NodeClick
The following code example demonstrates creating/opening the subdiagram using the NodeClick event:
[C#]
void EventSink_NodeClick(NodeMouseEventArgs evtArgs)
{
// Load the saved diagram file to the subdiagram that we want to open
if (evtArgs.Node.Name == "Venn Diagram")
{
subDiagram = diagram3;
subDiagram.Load("..//..//Venn Diagram.edd");
}
else
{
subDiagram = diagram2;
subDiagram.Load("..//..//StateDiagram.edd");
}if (subDiagram != null)
{
// Assign the current node's location to the subdiagram location
subDiagram.Location = new Point((int)evtArgs.Node.BoundingRectangle.X, (int)evtArgs.Node.BoundingRectangle.Y);
// Show the subdiagram
subDiagram.Show();
// Set the diagram bounds as the total bounds of the content
SizeF modelsize = subDiagram.Controller.GetBoundingRect(subDiagram.Model.Nodes, MeasureUnits.Pixel).Size;
subDiagram.Size = new Size((int)modelsize.Width, (int)modelsize.Height);
}
}
[VB]
Private Sub EventSink_NodeClick(ByVal evtArgs As NodeMouseEventArgs)
' Load the saved diagram file to the subdiagram that we want to open
If evtArgs.Node.Name = "Venn Diagram" Then
subDiagram = diagram3
subDiagram.Load("..//..//Venn Diagram.edd")
Else
subDiagram = diagram2
subDiagram.Load("..//..//StateDiagram.edd")
End IfIf subDiagram IsNot Nothing Then
' Assign the current node's location to the subdiagram location
subDiagram.Location = New Point(CInt(Fix(evtArgs.Node.BoundingRectangle.X)), CInt(Fix(evtArgs.Node.BoundingRectangle.Y)))
' Show the subdiagram
subDiagram.Show()
' Set the diagram bounds as the total bounds of the content
Dim modelsize As SizeF = subDiagram.Controller.GetBoundingRect(subDiagram.Model.Nodes, MeasureUnits.Pixel).Size
subDiagram.Size = New Size(CInt(Fix(modelsize.Width)), CInt(Fix(modelsize.Height)))
End If
End Sub
I hope you enjoyed learning about how to create/open the WinForms SubDiagram using NodeClick Events.
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 forums, Direct-Trac, or feedback portal. We are always happy to assist you!