Category / Section
Create/Open the SubDiagram using NodeClick Events
1 min read
Create/Open the SubDiagram using NodeClick Events
We don’t have built-in option to create/open a new sub-diagram. But we can achieve this requirement of opening the sub-diagram in application level. In this document, we are giving an example to create and open the sub-diagram in another diagram’s model using 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 for create/open the sub diagram using NodeClick event
[C#]
void EventSink_NodeClick(NodeMouseEventArgs evtArgs) { //load the saved diagram file to 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 sub diagram subDiagram.Show(); //setting the diagram bound as 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 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 If If 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 sub diagram subDiagram.Show() 'setting the diagram bound as 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
Sample: