Is it possible to arrange/re-arrange the diagram nodes automatically in some standard manner?
The various diagram layout managers that are shipped with the Diagram can be used to arrange/layout the nodes in the specified format. Please refer the samples under Diagram Samples/Layout Managers category to get the details about the various layout mangers and how to use this in a diagram application to arrange the nodes.
Below code snippet shows how to apply the layout mechanism on the diagram nodes.
C#
LayoutManager manager = new DirectedTreeLayoutManager(this.diagram.Model, 0,60,80 );
this.diagram.LayoutManager = manager;
VB
Private manager As LayoutManager = New DirectedTreeLayoutManager(Me.diagram.Model, 0,60,80)
Me.diagram.LayoutManager = manager
Once the layout manager has been assigned to the diagram, we can use either the LayoutManager.UpdateLayout() or LayoutManager.AutoLayout() to arrange the nodes in the specified layout.
The following code snippet shows how to arrange the nodes that are added/present in the diagram.
C#
this.diagram.BeginUpdate();
this.diagram.LayoutManager.Nodes.Clear();
this.diagram.LayoutManager.Nodes.AddRange(this.diagram.Model.Nodes );
// Updates the layout of the nodes in the model.
this.diagram.LayoutManager.UpdateLayout(null);
this.diagram.EndUpdate();
VB
Me.diagram.BeginUpdate()
Me.diagram.LayoutManager.Nodes.Clear()
Me.diagram.LayoutManager.Nodes.AddRange(Me.diagram.Model.Nodes)
'' Updates the layout of the nodes in the model.
Me.diagram.LayoutManager.UpdateLayout(Nothing)
Me.diagram.EndUpdate()
The following code snippet shows how to arrange the nodes as soon as that are added to the diagram.
C#
this.diagram.LayoutManager.AutoLayout = true;
VB
Me.diagram.LayoutManager.AutoLayout = True