No source code available.

// This sample demonstrates how to create
// simple diagram elements and how to
// adjust their visualization properties
// Create a new shape node
ShapeNode node = diagram.Factory.CreateShapeNode(10, 10, 36, 8);
// Specify the node's shape
node.Shape = Shapes.Ellipse;
// Modify the text displayed within the node and the font
// used to render the text
node.Text = "Start";
node.Font = new Font("Arial", 2.6f, GraphicsUnit.World);
// Modify the brush used to paint the node's interior
// and the pen used to draw its outline
node.Brush = new MindFusion.Drawing.LinearGradientBrush(
Color.FromArgb(0xff, 0xff, 0xff, 0xc0),
Color.FromArgb(0xff, 0xbf, 0xbf, 0x90), 90);
node.Pen = new MindFusion.Drawing.Pen(Color.Black, 0);
node.Pen.CompoundArray = new float[] { 0, 0.25f, 0.75f, 1 };
node.Pen.Width = 0.7f;

' This sample demonstrates how to create
' simple diagram elements and how to
' adjust their visualization properties
' Create a new shape node
Dim node As ShapeNode = diagram.Factory.CreateShapeNode(10, 10, 36, 8)
' Specify the node's shape
node.Shape = Shapes.Ellipse
' Modify the text displayed within the node and the font
' used to render the text
node.Text = "Start"
node.Font = New Font("Arial", 2.6f, GraphicsUnit.World)
' Modify the brush used to paint the node's interior
' and the pen used to draw its outline
node.Brush = New MindFusion.Drawing.LinearGradientBrush( _
Color.FromArgb(255, 255, 255, 192), _
Color.FromArgb(255, 191, 191, 144), 90)
node.Pen = New MindFusion.Drawing.Pen(Color.Black, 0)
node.Pen.CompoundArray = New Single() { 0, 0.25f, 0.75f, 1 }
node.Pen.Width = 0.7f

// This sample demonstrates how to make a
// node on the diagram resizing only horizontally
// Create a new shape node
ShapeNode node = diagram.Factory.CreateShapeNode(10, 10, 20, 10);
// Set the node's handles, so that only
// horizontal manipulations are possible
node.EnabledHandles = AdjustmentHandles.Move |
AdjustmentHandles.ResizeMiddleLeft | AdjustmentHandles.ResizeMiddleRight;
// Optionally, hide the disabled handles
diagram.ShowDisabledHandles = false;

' This sample demonstrates how to make a
' node on the diagram resizing only horizontally
' Create a new shape node
Dim node As ShapeNode = diagram.Factory.CreateShapeNode(10, 10, 20, 10)
' Set the node's handles, so that only
' horizontal manipulations are possible
node.EnabledHandles = AdjustmentHandles.Move + _
AdjustmentHandles.ResizeMiddleLeft + AdjustmentHandles.ResizeMiddleRight
' Optionally, hide the disabled handles
diagram.ShowDisabledHandles = False

// This sample demonstrates how to access the
// active (selected) element in a diagram and
// how to perform basic navigation in the graph
// The active diagram element is obtained via the
// ActiveItem property of the Diagram class
DiagramItem activeObj = diagram.ActiveItem;
// It is wise to check whether the object is null.
// This might happen when there is no selected object
if (activeObj == null)
return;
// Make sure the selected object is a DiagramNode
if (!(activeObj is DiagramNode))
return;
DiagramNode activeNode = activeObj as DiagramNode;
// Now it is possible to access the direct relatives of the active node
ArrayList relatives = new ArrayList();
foreach (DiagramLink link in activeNode.OutgoingLinks)
relatives.Add(link.Destination);
foreach (DiagramLink link in activeNode.IncomingLinks)
relatives.Add(link.Origin);

' This sample demonstrates how to access the
' active (selected) element in a diagram and
' how to perform basic navigation in the graph
' The active diagram element is obtained via the
' ActiveItem property of the Diagram object
Dim activeObj As DiagramItem = diagram.ActiveItem
' It is wise to check whether the object is Nothing.
' This might happen when there is no selected object
If activeObj Is Nothing Then
Return
End If
' Make sure the selected object is a DiagramNode
If Not Typeof activeObj Is DiagramNode Then
Return
End If
Dim activeNode As DiagramNode = CType(activeObj, DiagramNode)
' Now it is possible to access the direct relatives of the active node
Dim relatives As ArrayList = New ArrayList()
For Each link As DiagramLink In activeNode.OutgoingLinks
relatives.Add(link.Destination)
Next
For Each link As DiagramLink In activeNode.IncomingLinks
relatives.Add(link.Origin)
Next

// This sample demonstrates how to create groups
// Create two ShapeNode objects
ShapeNode master = diagram.Factory.CreateShapeNode(10, 10, 20, 8);
ShapeNode subordinate = diagram.Factory.CreateShapeNode(10, 25, 20, 8);
// Create the group, using the first ShapeNode as a master
Group group = diagram.Factory.CreateGroup(master);
// Now attach the second ShapeNode to the newly created group
group.AttachToCorner(subordinate, 0);

' This sample demonstrates how to create groups
' Create two ShapeNode objects
Dim master As ShapeNode = diagram.Factory.CreateShapeNode(10, 10, 20, 8)
Dim subordinate As ShapeNode = diagram.Factory.CreateShapeNode(10, 25, 20, 8)
' Create the group, using the first ShapeNode as a master
Dim group As Group = diagram.Factory.CreateGroup(master)
' Now attach the second ShapeNode to the newly created group
group.AttachToCorner(subordinate, 0)

// This sample demonstrates how to
// assign styled text to a ShapeNode
// Create a new ShapeNode
ShapeNode node = diagram.Factory.CreateShapeNode(10, 10, 40, 12);
// Set the node's style to, say, rectangle
node.Shape = Shapes.Rectangle;
// In order to use styled texts, two properties
// of the node need to be set - EnableStyledText
// and PolygonalTextLayout
node.EnableStyledText = true;
node.PolygonalTextLayout = true;
// Now assign the formatted text to the node
node.Text = "<color=#ff0000> HCl</color> + NaOH = H<sub> 2</sub> O + NaCl";

' This sample demonstrates how to
' assign styled text to a ShapeNode
' Create a new ShapeNode
Dim node As ShapeNode = diagram.Factory.CreateShapeNode(10, 10, 40, 12)
' Set the node's style to, say, rectangle
node.Shape = Shapes.Rectangle
' In order to use styled texts, two properties
' of the node need to be set - EnableStyledText
' and PolygonalTextLayout
node.EnableStyledText = True
node.PolygonalTextLayout = True
' Now assign the formatted text to the node
node.Text = "<color=#ff0000> HCl</color> + NaOH = H<sub> 2</sub> O + NaCl"

// This sample demonstrates how nodes can be
// linked together with links and how to
// enable expanding or collapsing nodes
// Setting the default property NodesExpandable
// of the Diagram object indicates that all
// subsequently created shape nodes will be expandable
diagram.NodesExpandable = true;
// Create two ShapeNode objects
ShapeNode parent = diagram.Factory.CreateShapeNode(10, 10, 20, 8);
ShapeNode child = diagram.Factory.CreateShapeNode(10, 25, 20, 8);
// Link the ShapeNode objects together by creating a new
// link from the parent ShapeNode to the child ShapeNode
diagram.Factory.CreateDiagramLink(parent, child);

' This sample demonstrates how nodes can be
' linked together with links and how to
' enable expanding or collapsing nodes
' Setting the default property NodesExpandable
' of the Diagram object indicates that all
' subsequently created shape nodes will be expandable
diagram.NodesExpandable = True
' Create two ShapeNode objects
Dim parent As ShapeNode = diagram.Factory.CreateShapeNode(10, 10, 20, 8)
Dim child As ShapeNode = diagram.Factory.CreateShapeNode(10, 25, 20, 8)
' Link the ShapeNodes together by creating a new
' link from the parent ShapeNode to the child ShapeNode
diagram.Factory.CreateDiagramLink(parent, child)

// This sample demonstrates how to apply
// custom drawing code to ShapeNode objects in MindFusion.Diagramming
// ... initialization ...
// Attach new event handler to the Diagram.DrawNode
// event. All of the custom drawing should be placed
// in that handler
diagram.DrawNode += OnDrawNode;
// Create a sample ShapeNode and enable custom drawing
ShapeNode node = diagram.Factory.CreateShapeNode(10, 10, 40, 30);
node.CustomDraw = CustomDraw.Additional;
// ... more initialization ...
// Custom drawing event handler
private void OnDrawNode(object sender, DrawNodeEventArgs e)
{
// Draw big red ellipse in the center of the ShapeNode
System.Drawing.Pen redPen = new System.Drawing.Pen(Color.Red, 0.5f);
RectangleF nodeBounds = e.Bounds;
nodeBounds.Inflate(-nodeBounds.Width / 4, -nodeBounds.Height / 4);
e.Graphics.DrawEllipse(redPen, nodeBounds);
redPen.Dispose();
}

' This sample demonstrates how to apply
' custom drawing code to ShapeNode objects in MindFusion.Diagramming
' ... initialization ...
' Attach new event handler to the Diagram.DrawNode
' event. All of the custom drawing should be placed
' in that handler
AddHandler diagram.DrawNode, AddressOf OnDrawNode
' Create a sample ShapeNode and enable custom drawing
Dim node As ShapeNode = diagram.Factory.CreateShapeNode(10, 10, 40, 30)
node.CustomDraw = CustomDraw.Additional
' ... more initialization ...
' Custom drawing event handler
Private Sub OnDrawNode(sender As Object, e As DrawNodeEventArgs)
' Draw big red ellipse in the center of the ShapeNode
Dim redPen As System.Drawing.Pen = New System.Drawing.Pen(Color.Red, 0.5f)
Dim nodeBounds As RectangleF = e.Bounds
nodeBounds.Inflate(-nodeBounds.Width / 4, -nodeBounds.Height / 4)
e.Graphics.DrawEllipse(redPen, nodeBounds)
redPen.Dispose()
End Sub

// This sample demonstrates how to
// associate anchor patterns with table rows
// Create a sample table first
TableNode table = diagram.Factory.CreateTableNode(10, 10, 40, 25);
// Modify the number of rows and columns
table.RowCount = 2;
table.ColumnCount = 3;
// Adjust the table columns
table.Columns[0].Width = 10;
table.Columns[1].Width = 20;
table.Columns[2].Width = 10;
table.Columns[0].ColumnStyle = MindFusion.Diagramming.ColumnStyle.FixedWidth;
table.Columns[1].ColumnStyle = MindFusion.Diagramming.ColumnStyle.AutoWidth;
table.Columns[2].ColumnStyle = MindFusion.Diagramming.ColumnStyle.FixedWidth;
// Create an anchor pattern to be assigned to the table
AnchorPattern pattern = new AnchorPattern(
new AnchorPoint[]
{
new AnchorPoint(50, 50, true, false, Color.Blue, 0),
new AnchorPoint(50, 50, false, true, Color.Blue, 2)
});
// Set the newly created anchor
// pattern to be used for all rows
table.RowAnchorPattern = pattern;

' This sample demonstrates how to
' associate anchor patterns with table rows
' Create a sample table first
Dim table As TableNode = diagram.Factory.CreateTableNode(10, 10, 40, 25)
' Modify the number of rows and columns
table.RowCount = 2
table.ColumnCount = 3
' Adjust the table columns
table.Columns(0).Width = 10
table.Columns(1).Width = 20
table.Columns(2).Width = 10
table.Columns(0).ColumnStyle = MindFusion.Diagramming.ColumnStyle.FixedWidth
table.Columns(1).ColumnStyle = MindFusion.Diagramming.ColumnStyle.AutoWidth
table.Columns(2).ColumnStyle = MindFusion.Diagramming.ColumnStyle.FixedWidth
' Create an anchor pattern to be assigned to the table
Dim pattern As New AnchorPattern( _
New AnchorPoint() _
{ _
New AnchorPoint(50, 50, True, False, Color.Blue, 0), _
New AnchorPoint(50, 50, False, True, Color.Blue, 2) _
})
' Set the newly created anchor
' pattern to be used for all rows
table.RowAnchorPattern = pattern

// This sample demonstrates how to
// enable scrolling of table rows
// Create and setup a new table
TableNode table = diagram.Factory.CreateTableNode(10, 10, 30, 45);
table.RedimTable(1, 20);
for (int i = 0; i < table.RowCount; i++)
table[0, i].Text = "Row" + i.ToString();
// Enable scrolling
table.Scrollable = true;

' This sample demonstrates how to
' enable scrolling of table rows
' Create and setup a new table
Dim table As TableNode = diagram.Factory.CreateTableNode(10, 10, 30, 45)
table.RedimTable(1, 20)
Dim i As Integer
For i = 0 To table.RowCount - 1
table(0, i).Text = "Row" + i.ToString()
Next
' Enable scrolling
table.Scrollable = True

// This sample demonstrates how to link tables
// programatically and how to set up links' heads
// Create two related tables
TableNode t1 = diagram.Factory.CreateTableNode(10, 10, 30, 35);
TableNode t2 = diagram.Factory.CreateTableNode(70, 10, 30, 35);
// Setup tables
t1.RedimTable(1, 2);
t2.RedimTable(1, 2);
// Create a link which connects the tables
DiagramLink link = diagram.Factory.CreateDiagramLink(t1, 0, t2, 1);
// Set the link style to cascading
link.SegmentCount = 3;
link.Shape = LinkShape.Cascading;
link.CascadeOrientation =
MindFusion.Diagramming.Orientation.Horizontal;
// Finally modify the link's heads
link.BaseShape = ArrowHeads.RevTriangle;
link.BaseShapeSize = 2;
link.HeadShape = ArrowHeads.Tetragon;
link.HeadShapeSize = 5;

' This sample demonstrates how to link tables
' programatically and how to set up links' heads
' Create two related tables
Dim t1 As TableNode = diagram.Factory.CreateTableNode(10, 10, 30, 35)
Dim t2 As TableNode = diagram.Factory.CreateTableNode(70, 10, 30, 35)
' Setup tables
t1.RedimTable(1, 2)
t2.RedimTable(1, 2)
' Create a link which connects the tables
Dim link As DiagramLink = diagram.Factory.CreateDiagramLink(t1, 0, t2, 1)
' Set the link style to cascading
link.SegmentCount = 3
link.Shape = LinkShape.Cascading
link.CascadeOrientation = _
MindFusion.Diagramming.Orientation.Horizontal
' Finally modify the link's heads
link.BaseShape = ArrowHeads.RevTriangle
link.BaseShapeSize = 2
link.HeadShape = ArrowHeads.Tetragon
link.HeadShapeSize = 5

// This sample demonstrates how to create
// spanning cells and header rows in a MindFusion.Diagramming table
// Create a table
TableNode table = diagram.Factory.CreateTableNode(10, 10, 30, 40);
// Setup the number of rows and columns in the table
table.RedimTable(2, 5);
// Mark the first and the fourth rows as headers
table.Rows[0].Header = true;
table.Rows[3].Header = true;
// Span the cells in the header rows to cover the entire rows
table[0, 0].ColumnSpan = 2;
table[0, 0].Text = "Header 1";
table[0, 3].ColumnSpan = 2;
table[0, 3].Text = "Header 2";
// Span the cells from the second column below the first header row
table[1, 1].RowSpan = 2;
table[1, 1].Text = "span";
// Offset the header rows, so that the 'expand/collapse'
// icon is positioned on the left
table.OffsetHeaderRows = true;

' This sample demonstrates how to create
' spanning cells and header rows in a MindFusion.Diagramming table
' Create a table
Dim table As TableNode = diagram.Factory.CreateTableNode(10, 10, 30, 40)
' Setup the number of rows and columns in the table
table.RedimTable(2, 5)
' Mark the first and the fourth rows as headers
table.Rows(0).Header = True
table.Rows(3).Header = True
' Span the cells in the header rows to cover the entire rows
table(0, 0).ColumnSpan = 2
table(0, 0).Text = "Header 1"
table(0, 3).ColumnSpan = 2
table(0, 3).Text = "Header 2"
' Span the cells from the second column below the first header row
table(1, 1).RowSpan = 2
table(1, 1).Text = "span"
' Offset the header rows, so that the 'expand/collapse'
' icon is positioned on the left
table.OffsetHeaderRows = True

// This sample demonstrates how to create interactive
// ShapeNode objects, which behave much like buttons
// Create a ShapeNode to be used as a button
ShapeNode node = diagram.Factory.CreateShapeNode(10, 10, 20, 10);
node.Shape = Shapes.Rectangle;
node.Text = "Click me";
node.Tag = "button";
// Associate an event handler with the
// Diagram.NodeClicked event
diagram.NodeClicked += OnNodeClicked;
// ...
// NodeClicked event handler
private void OnNodeClicked(object sender, NodeEventArgs e)
{
if ((string)e.Node.Tag == "button")
{
// The button-node has been clicked
MessageBox.Show("Click!");
}
}

' This sample demonstrates how to create interactive
' ShapeNode objects, which behave much like buttons
' Create a ShapeNode to be used as a button
Dim node As ShapeNode = diagram.Factory.CreateShapeNode(10, 10, 20, 10)
node.Shape = Shapes.Rectangle
node.Text = "Click me"
node.Tag = "button"
' Associate an event handler with the
' Diagram.NodeClicked event
AddHandler diagram.NodeClicked, AddressOf OnNodeClicked
' ...
' NodeClicked event handler
Private Sub OnNodeClicked(sender As Object, e As NodeEventArgs)
If CType(e.Node.Tag, String) = "button" Then
' The button-node has been clicked
MessageBox.Show("Click!")
End If
End Sub

// This sample demonstrates how to host
// .NET Windows.Forms controls in diagram nodes
// Create the controls to be hosted
TextBox textBox = new System.Windows.Forms.TextBox();
Button button = new System.Windows.Forms.Button();
// Initialize the controls
textBox.Text = "Hello, world!";
button.Click += new EventHandler(OnClick);
button.Text = "Show";
// Create two ControlNode objects
ControlNode editNode = new ControlNode();
editNode.Bounds = new RectangleF(10, 10, 40, 8);
diagram.Nodes.Add(editNode);
ControlNode buttonNode = new ControlNode();
buttonNode.Bounds = new RectangleF(10, 20, 40, 8);
diagram.Nodes.Add(buttonNode);
// Setup hosts
editNode.Control = textBox;
editNode.Tag = "edit";
buttonNode.Control = button;
// ...
private void OnClick(object sender, EventArgs e)
{
// Show a message box with the text currently
// displayed within the TextBox control
ControlNode host = (ControlNode)diagram.FindNode("edit");
if (host != null)
MessageBox.Show(host.Control.Text);
}

' This sample demonstrates how to host
' .NET Windows.Forms controls in diagram nodes
' Create the controls to be hosted
Dim textBox As TextBox = New System.Windows.Forms.TextBox()
Dim button As Button = New System.Windows.Forms.Button()
' Initialize the controls
textBox.Text = "Hello, world!"
AddHandler button.Click, AddressOf OnClick
button.Text = "Show"
' Create two ControlNode objects
Dim editNode As New ControlNode()
editNode.Bounds = New RectangleF(10, 10, 40, 8)
diagram.Nodes.Add(editNode)
Dim buttonNode As New ControlNode()
buttonNode.Bounds = New RectangleF(10, 20, 40, 8)
diagram.Nodes.Add(buttonNode)
' Setup hosts
editNode.Control = textBox
editNode.Tag = "edit"
buttonNode.Control = button
' ...
Private Overloads Sub OnClick(sender As Object, e As EventArgs)
' Show a message box with the text currently
' displayed within the TextBox control
Dim host As ControlNode = CType(diagram.FindNode("edit"), ControlNode)
If Not host Is Nothing Then
MessageBox.Show(host.Control.Text)
End If
End Sub

public class MyControl : System.Windows.Forms.Panel
{
public MyControl()
{
this.Size = new Size(57, 22);
textBox = new TextBox();
button = new Button();
textBox.Text = "Text";
textBox.Anchor = AnchorStyles.Left | AnchorStyles.Right |
AnchorStyles.Top | AnchorStyles.Bottom;
textBox.Multiline = true;
textBox.Size = new Size(10, 20);
textBox.Location = new Point(1, 1);
button.Text = "Button";
button.Anchor = AnchorStyles.Right | AnchorStyles.Top;
button.Click += new EventHandler(OnClick);
button.Size = new Size(46, 20);
button.Location = new Point(11, 1);
this.Controls.Add(textBox);
this.Controls.Add(button);
}
private void OnClick(object sender, EventArgs e)
{
MessageBox.Show(textBox.Text);
}
private TextBox textBox;
private Button button;
}
// ...
// Create a new diagram node and host an
// instance of the custom control in it
ControlNode host = new ControlNode();
host.Bounds = new RectangleF(10, 10, 40, 15);
host.Control = new MyControl();
diagram.Nodes.Add(host);
diagramView.Behavior = Behavior.LinkControls;
diagramView.DefaultControlType = typeof(MyControl);

Public Class MyControl
Inherits System.Windows.Forms.Panel
Public Sub New()
Me.Size = New Size(57, 22)
textBox = New TextBox()
button = New Button()
textBox.Text = "Text"
textBox.Anchor = AnchorStyles.Left + AnchorStyles.Right + _
AnchorStyles.Top + AnchorStyles.Bottom
textBox.Multiline = True
textBox.Size = New Size(10, 20)
textBox.Location = New Point(1, 1)
button.Text = "Button"
button.Anchor = AnchorStyles.Right + AnchorStyles.Top
AddHandler button.Click, AddressOf OnClick
button.Size = New Size(46, 20)
button.Location = New Point(11, 1)
Me.Controls.Add(textBox)
Me.Controls.Add(button)
End Sub
Private Overloads Sub OnClick(sender As Object, e As EventArgs)
MessageBox.Show(textBox.Text)
End Sub
Private textBox As TextBox
Private button As Button
End Class
' ...
' Create a new diagram node and host an
' instance of the custom control in it
Dim host As New ControlNode()
host.Bounds = New RectangleF(10, 10, 40, 15)
host.Control = New MyControl()
diagram.Nodes.Add(host)
diagramView.Behavior = Behavior.LinkControls
diagramView.DefaultControlType = GetType(MyControl)

// This sample demonstrates how to link
// control nodes programmatically
// Create two control nodes
ControlNode host1 = new ControlNode();
ControlNode host2 = new ControlNode();
host1.Bounds = new RectangleF(10, 10, 15, 10);
host2.Bounds = new RectangleF(45, 15, 15, 10);
diagram.Nodes.Add(host1);
diagram.Nodes.Add(host2);
// Linking of control nodes is
// identical to that of ShapeNodes
diagram.Factory.CreateDiagramLink(host1, host2);

' This sample demonstrates how to link
' control nodes programmatically
' Create two control nodes
Dim host1 As New ControlNode()
Dim host2 As New ControlNode()
host1.Bounds = New RectangleF(10, 10, 15, 10)
host2.Bounds = New RectangleF(45, 15, 15, 10)
diagram.Nodes.Add(host1)
diagram.Nodes.Add(host2)
' Linking of control nodes is
' identical to that of ShapeNodes
diagram.Factory.CreateDiagramLink(host1, host2)

// This sample demonstrates the use of link heads
// Create the two ShapeNode objects to be connected with a link
ShapeNode startNode, endNode;
startNode = diagram.Factory.CreateShapeNode(10, 10, 8, 8);
endNode = diagram.Factory.CreateShapeNode(40, 10, 8, 8);
// Create the link
DiagramLink link = diagram.Factory.CreateDiagramLink(startNode, endNode);
// Modify the link's head
link.HeadShape = ArrowHeads.BowArrow;
link.HeadShapeSize = 6;
// Modify the link's base
link.BaseShape = ArrowHeads.Circle;
link.BaseShapeSize = 4;
// Modify the intermediate heads
link.IntermediateShape = ArrowHeads.PointerArrow;
link.IntermediateShapeSize = 3;
// Create cool pen for all heads
link.HeadPen = new MindFusion.Drawing.Pen(Color.Black, 0);
link.HeadPen.CompoundArray = new float[] { 0, 0.5f, 0.8f, 1 };
link.HeadPen.Width = 0.8f;

' This sample demonstrates the use of link heads
' Create the two ShapeNode objects to be connected with a link
Dim startNode, endNode As ShapeNode
startNode = diagram.Factory.CreateShapeNode(10, 10, 8, 8)
endNode = diagram.Factory.CreateShapeNode(40, 10, 8, 8)
' Create the link
Dim link As DiagramLink = diagram.Factory.CreateDiagramLink(startNode, endNode)
' Modify the link's head
link.HeadShape = ArrowHeads.BowArrow
link.HeadShapeSize = 6
' Modify the link's base
link.BaseShape = ArrowHeads.Circle
link.BaseShapeSize = 4
' Modify the intermediate heads
link.IntermediateShape = ArrowHeads.PointerArrow
link.IntermediateShapeSize = 3
' Create cool pen for all heads
link.HeadPen = New MindFusion.Drawing.Pen(Color.Black, 0)
link.HeadPen.CompoundArray = New Single() { 0, 0.5f, 0.8f, 1 }
link.HeadPen.Width = 0.8f

// This sample demonstrates how to route all
// links on a diagram with a single call
diagram.RouteAllLinks();

' This sample demonstrates how to route all
' links on a diagram with a single call
diagram.RouteAllLinks()

// This sample demonstrates how to modify
// the orientation of a link's text
// Create two nodes and a link which connects them
ShapeNode startNode = diagram.Factory.CreateShapeNode(10, 10, 8, 8);
ShapeNode endNode = diagram.Factory.CreateShapeNode(60, 25, 8, 8);
DiagramLink link = diagram.Factory.CreateDiagramLink(startNode, endNode);
// Set the text and font of the link
link.Text = "some slanted text";
link.Font = new Font("Arial", 3, FontStyle.Bold, GraphicsUnit.World);
// Finally set the text orientation of the link
link.TextStyle = LinkTextStyle.Rotate;

' This sample demonstrates how to modify
' the orientation of a link's text
' Create two nodes and a link which connects them
Dim startNode As ShapeNode = diagram.Factory.CreateShapeNode(10, 10, 8, 8)
Dim endNode As ShapeNode = diagram.Factory.CreateShapeNode(60, 25, 8, 8)
Dim link As DiagramLink = diagram.Factory.CreateDiagramLink(startNode, endNode)
' Set the text and font of the link
link.Text = "some slanted text"
link.Font = New Font("Arial", 3, FontStyle.Bold, GraphicsUnit.World)
' Finally set the text orientation of the link
link.TextStyle = LinkTextStyle.Rotate

// This sample demonstrates how to create
// unconnected links programmatically,
// how to manipulate individual link points
// and how to 'tell' a link to preserve its contour
// Create an unconnected link
DiagramLink link = diagram.Factory.CreateDiagramLink(
new PointF(10, 20), new PointF(50, 20));
link.Shape = LinkShape.Polyline;
link.SegmentCount = 4;
// Modify the control points
Random g = new Random();
for (int i = 1; i < link.ControlPoints.Count - 1; i++)
{
PointF point = link.ControlPoints[i];
point.X += g.Next(-4, 4);
point.Y += g.Next(-10, 10);
link.ControlPoints[i] = point;
}
// After modifying the control points of a link
// it is necessary to invoke DiagramLink.UpdateFromPoints
// method to update the link's heads and various
// internal variables
link.UpdateFromPoints();
// Finally make the link persist its contour
link.RetainForm = true;

' This sample demonstrates how to create
' unconnected links programmatically,
' how to manipulate individual link points
' and how to 'tell' a link to preserve its contour
' Create an unconnected link
Dim link As DiagramLink = diagram.Factory.CreateDiagramLink( _
New PointF(10, 20), New PointF(50, 20))
link.Shape = LinkShape.Polyline
link.SegmentCount = 4
' Modify the control points
Dim g As New Random()
Dim i As Integer
For i = 1 To link.ControlPoints.Count - 2
Dim point As PointF = link.ControlPoints(i)
point.X = point.X + g.Next(-4, 4)
point.Y = point.Y + g.Next(-10, 10)
link.ControlPoints(i) = point
Next
' After modifying the control points of a link
' it is necessary to invoke DiagramLink.UpdateFromPoints
' method to update the link's heads and various
' internal variables
link.UpdateFromPoints()
' Finally make the link persist its contour
link.RetainForm = True

// This sample demonstrates how to perform
// custom drawing on a link
// Create two nodes
ShapeNode n1 = diagram.Factory.CreateShapeNode(10, 10, 10, 10);
ShapeNode n2 = diagram.Factory.CreateShapeNode(30, 50, 10, 10);
// Link the nodes with a link
DiagramLink link = diagram.Factory.CreateDiagramLink(n1, n2);
link.Selected = false;
// Mark the link as custom-drawn
link.CustomDraw = CustomDraw.Additional;
// Handle the DrawLink event, which gets fired
// whenever the link is being drawn
diagram.DrawLink += OnDrawLink;
// ...
private void OnDrawLink(object sender, DrawLinkEventArgs e)
{
// Draw a small rectangle at the base of the link
PointF a = e.Link.ControlPoints[0];
System.Drawing.Pen pen = new System.Drawing.Pen(Color.Black, 0);
e.Graphics.FillRectangle(Brushes.Red, a.X - 1, a.Y - 1, 2, 2);
e.Graphics.DrawRectangle(pen, a.X - 1, a.Y - 1, 2, 2);
pen.Dispose();
}

' This sample demonstrates how to perform
' custom drawing on a link
' Create two nodes
Dim n1 As ShapeNode = diagram.Factory.CreateShapeNode(10, 10, 10, 10)
Dim n2 As ShapeNode = diagram.Factory.CreateShapeNode(30, 50, 10, 10)
' Link the nodes with a link
Dim link As DiagramLink = diagram.Factory.CreateDiagramLink(n1, n2)
link.Selected = False
' Mark the link as custom-drawn
link.CustomDraw = CustomDraw.Additional
' Handle the DrawLink event, which gets fired
' whenever the link is being drawn
AddHandler diagram.DrawLink, AddressOf OnDrawLink
' ...
Private Sub OnDrawLink(sender As Object, e As DrawLinkEventArgs)
' Draw a small rectangle at the base of the link
Dim a As PointF = e.Link.ControlPoints(0)
Dim pen As New System.Drawing.Pen(Color.Black, 0)
e.Graphics.FillRectangle(Brushes.Red, a.X - 1, a.Y - 1, 2, 2)
e.Graphics.DrawRectangle(pen, a.X - 1, a.Y - 1, 2, 2)
pen.Dispose()
End Sub

// This sample demonstrates how to
// apply tree layout to a diagram
// Create the layouter object
TreeLayout layout = new TreeLayout();
// Adjust the attributes of the layouter
layout.LinkStyle = TreeLayoutLinkType.Rounded;
layout.Type = TreeLayoutType.Centered;
layout.KeepRootPosition = true;
// Load a sample diagram
diagram.LoadFromFile("14.fns");
// Perform the actual arrangement
layout.Arrange(diagram);
// Fit contents within the document
diagram.ResizeToFitItems(5);

' This sample demonstrates how to
' apply tree layout to a diagram
' Create the layouter object
Dim layout As New TreeLayout()
' Adjust the attributes of the layouter
layout.LinkStyle = TreeLayoutLinkType.Rounded
layout.Type = TreeLayoutType.Centered
layout.KeepRootPosition = True
' Load a sample diagram
diagram.LoadFromFile("14.fns")
' Perform the actual arrangement
layout.Arrange(diagram)
' Fit contents within the document
diagram.ResizeToFitItems(5)

// This sample demonstrates how to apply
// radial tree layout to hierarchical
// data structures (that is, trees)
// Create the layouter object
TreeLayout layout = new TreeLayout();
// Specify the type of tree layout to apply
layout.Type = TreeLayoutType.Radial;
layout.LevelDistance = 15;
// Build a random tree diagram
ShapeNode root = diagram.Factory.CreateShapeNode(0, 0, 7.5f, 7.5f);
BuildBranch(root, new Random(), 10);
// Perform the actual arrangement
layout.Arrange(diagram);
// ...
private void BuildBranch(ShapeNode parent, Random g, int maxSteps)
{
if (maxSteps < 2)
return;
int steps = g.Next(2, maxSteps);
for (int i = 0; i < steps; i++)
{
// Create new node and link it to its parent
ShapeNode child = diagram.Factory.CreateShapeNode(0, 0, 7.5f, 7.5f);
diagram.Factory.CreateDiagramLink(parent, child);
// Continue building recursively
BuildBranch(child, g, steps - g.Next(1, 2));
}
}

' This sample demonstrates how to apply
' radial tree layout to hierarchical
' data structures (that is, trees)
' Create the layouter object
Dim layout As New TreeLayout()
' Specify the type of tree layout to apply
layout.Type = TreeLayoutType.Radial
layout.LevelDistance = 15
' Build a random tree diagram
Dim root As ShapeNode = diagram.Factory.CreateShapeNode(0, 0, 7.5f, 7.5f)
BuildBranch(root, new Random(), 10)
' Perform the actual arrangement
layout.Arrange(diagram)
' ...
Private Sub BuildBranch(parent As ShapeNode, g As Random, maxSteps As Integer)
If maxSteps < 2 Then
Return
End If
Dim steps As Integer = g.Next(2, maxSteps)
Dim i As Integer
For i = 0 To steps - 1
' Create new node and link it to its parent
Dim child As ShapeNode = diagram.Factory.CreateShapeNode(0, 0, 7.5f, 7.5f)
diagram.Factory.CreateDiagramLink(parent, child)
' Continue building recursively
BuildBranch(child, g, steps - g.Next(1, 2))
Next
End Sub

// This sample demonstrates how to
// apply spring layout to a graph
// Create the layouter object
SpringLayout layout = new SpringLayout();
// Adjust the attributes of the layouter
layout.IterationCount = 500;
layout.MinimizeCrossings = true;
// Load a sample diagram
diagram.LoadFromFile("15.fns");
// Perform the actual arrangement
layout.Arrange(diagram);
// Fit contents within the document
diagram.ResizeToFitItems(5);

' This sample demonstrates how to
' apply spring layout to a graph
' Create the layouter object
Dim layout As New SpringLayout()
' Adjust the attributes of the layouter
layout.IterationCount = 500
layout.MinimizeCrossings = True
' Load a sample diagram
diagram.LoadFromFile("15.fns")
' Perform the actual arrangement
layout.Arrange(diagram)
' Fit contents within the document
diagram.ResizeToFitItems(5)

// This sample demonstrates the simplest way
// to apply layered layout to a graph
// Create the layouter object
LayeredLayout layout = new LayeredLayout();
// Load a sample diagram
diagram.LoadFromFile("25.fns");
// Perform the actual arrangement
layout.Arrange(diagram);
// Fit contents within the document
diagram.ResizeToFitItems(5);

' This sample demonstrates the simplest way
' to apply layered layout to a graph
' Create the layouter object
Dim layout As New LayeredLayout()
' Load a sample diagram
diagram.LoadFromFile("25.fns")
' Perform the actual arrangement
layout.Arrange(diagram)
' Fit contents within the document
diagram.ResizeToFitItems(5)

// This sample demonstrates how to
// apply grid layout to a graph
// Create the layouter object
GridLayout layout = new GridLayout();
// Adjust the attributes of the layouter
layout.Iterations = 1000;
layout.GridSize = 20;
// Load a sample diagram
diagram.LoadFromFile("27.fns");
// Perform the actual arrangement
layout.Arrange(diagram);
// Fit contents within the document
diagram.ResizeToFitItems(5);

' This sample demonstrates how to
' apply grid layout to a graph
' Create the layouter object
Dim layout As New GridLayout()
' Adjust the attributes of the layouter
layout.Iterations = 1000
layout.GridSize = 20
' Load a sample diagram
diagram.LoadFromFile("27.fns")
' Perform the actual arrangement
layout.Arrange(diagram)
' Fit contents within the document
diagram.ResizeToFitItems(5)

// This sample demonstrates how to
// apply clustered spring layout to a graph
// Create the layouter object
SpringLayout layout = new SpringLayout();
// Adjust the attributes of the layouter
layout.IterationCount = 200;
layout.EnableClusters = true;
layout.NodeDistance = 8;
layout.RepulsionFactor = 1;
layout.MinimizeCrossings = false;
// Load a sample diagram
diagram.LoadFromFile("28.fns");
// Perform the actual arrangement
layout.Arrange(diagram);
// Fit contents within the document
diagram.ResizeToFitItems(5);

' This sample demonstrates how to
' apply clustered spring layout to a graph
' Create the layouter object
Dim layout As New SpringLayout()
' Adjust the attributes of the layouter
layout.IterationCount = 200
layout.EnableClusters = True
layout.NodeDistance = 8
layout.RepulsionFactor = 1
layout.MinimizeCrossings = False
' Load a sample diagram
diagram.LoadFromFile("28.fns")
' Perform the actual arrangement
layout.Arrange(diagram)
' Fit contents within the document
diagram.ResizeToFitItems(5)

// This sample demonstrates how to access
// all successors (either direct or indirect) of a node
// Load a sample diagram
diagram.LoadFromFile("10.fns");
// Check if there is an active node in the diagram
if (!(diagram.ActiveItem is ShapeNode))
return;
// A list where the successor nodes will be stored
ArrayList successors = new ArrayList();
// A temporary queue containing nodes which are yet to be visited
Queue remaining = new Queue();
remaining.Enqueue(diagram.ActiveItem as ShapeNode);
while (remaining.Count > 0)
{
ShapeNode node = remaining.Dequeue() as ShapeNode;
// Traverse all outgoing links and add their
// destination nodes to the successor list
foreach (DiagramLink link in node.OutgoingLinks)
{
if (!successors.Contains(link.Destination))
{
successors.Add(link.Destination);
remaining.Enqueue(link.Destination);
}
}
}
// Color the successor nodes
foreach (ShapeNode node in successors)
node.Brush = new MindFusion.Drawing.SolidBrush(Color.LightGreen);

' This sample demonstrates how to access
' all successors (either direct or indirect) of a node
' Load a sample diagram
diagram.LoadFromFile("10.fns")
' Check if there is an active node in the diagram
If Not TypeOf diagram.ActiveItem Is ShapeNode Then
Return
End If
' A list where the successor nodes will be stored
Dim successors As New ArrayList()
' A temporary queue containing nodes which are yet to be visited
Dim remaining As New Queue()
remaining.Enqueue(CType(diagram.ActiveItem, ShapeNode))
While remaining.Count > 0
Dim node As ShapeNode = CType(remaining.Dequeue(), ShapeNode)
' Traverse all outgoing links and add their
' destination nodes to the successor list
For Each link As DiagramLink In node.OutgoingLinks
If Not successors.Contains(link.Destination) Then
successors.Add(link.Destination)
remaining.Enqueue(link.Destination)
End If
Next
End While
' Color the successor nodes
For Each node As ShapeNode in successors
node.Brush = New MindFusion.Drawing.SolidBrush(Color.LightGreen)
Next

// This sample demonstrates how easy it is
// to find paths in MindFusion.Diagramming graphs
// Load a sample diagram
diagram.LoadFromFile("5.fns");
// Make sure there are at least two nodes in the diagram
if (diagram.Nodes.Count < 2)
return;
// Use the MindFusion.Diagramming.PathFinder class
// to find paths and cycles in any graph
PathFinder pathFinder = new PathFinder(diagram);
Path p = pathFinder.FindShortestPath(diagram.Nodes[0],
diagram.Nodes[diagram.Nodes.Count - 1]);
// If the returned reference is null, no path
// has been found
if (p == null)
{
MessageBox.Show("No path found!");
return;
}
// Color the path
foreach (ShapeNode node in p.Nodes)
{
node.Brush = new MindFusion.Drawing.SolidBrush(Color.Yellow);
node.Pen = new MindFusion.Drawing.Pen(Color.Red);
}
foreach (DiagramLink link in p.Links)
link.Pen = new MindFusion.Drawing.Pen(Color.Red);

' This sample demonstrates how easy it is
' to find paths in MindFusion.Diagramming graphs
' Load a sample diagram
diagram.LoadFromFile("5.fns")
' Make sure there are at least two nodes in the diagram
If diagram.Nodes.Count < 2 Then
Return
End If
' Use the MindFusion.Diagramming.PathFinder class
' to find paths and cycles in any graph
Dim pathFinder As New PathFinder(diagram)
Dim p As Path = pathFinder.FindShortestPath(diagram.Nodes(0), _
diagram.Nodes(diagram.Nodes.Count - 1))
' If the returned reference is Nothing, no path
' has been found
If p Is Nothing Then
MessageBox.Show("No path found!")
Return
End If
' Color the path
For Each node As ShapeNode In p.Nodes
node.Brush = New MindFusion.Drawing.SolidBrush(Color.Yellow)
node.Pen = New MindFusion.Drawing.Pen(Color.Red)
Next
For Each link As DiagramLink In p.Links
link.Pen = New MindFusion.Drawing.Pen(Color.Red)
Next

// This sample demonstrates how to rotate
// nodes at arbitrary angles
// Create a ShapeNode
ShapeNode node = diagram.Factory.CreateShapeNode(10, 10, 25, 25);
// Only ShapeNode objects can be rotated
node.Shape = Shapes.Decision;
// Rotate the node now at 30 degrees
node.RotationAngle = 30;
// Set some text in the node and make the text rotate as well
node.Text = "Rotated node";
node.Font = new Font("Arial", 12, FontStyle.Bold);
node.RotateText = true;

' This sample demonstrates how to rotate
' nodes at arbitrary angles
' Create a ShapeNode
Dim node As ShapeNode = diagram.Factory.CreateShapeNode(10, 10, 25, 25)
' Only ShapeNode objects can be rotated
node.Shape = Shapes.Decision
' Rotate the node now at 30 degrees
node.RotationAngle = 30
' Set some text in the node and make the text rotate as well
node.Text = "Rotated node"
node.Font = New Font("Arial", 12, FontStyle.Bold)
node.RotateText = True

// This sample demonstrates how to proportionally attach
// nodes to each other using MindFusion.Diagramming groups
// Create a TableNode and a ShapeNode
TableNode master = diagram.Factory.CreateTableNode(10, 10, 20, 40);
ShapeNode subordinate = diagram.Factory.CreateShapeNode(10, 50, 20, 8);
// Create a group, using the table as a master
Group group = diagram.Factory.CreateGroup(master);
// Attach the box to the newly created group
group.AttachProportional(subordinate, 0, 100, 100, 120);

' This sample demonstrates how to proportionally attach
' nodes to each other using MindFusion.Diagramming groups
' Create a TableNode and a ShapeNode
Dim master As TableNode = diagram.Factory.CreateTableNode(10, 10, 20, 40)
Dim subordinate As ShapeNode = diagram.Factory.CreateShapeNode(10, 50, 20, 8)
' Create a group, using the table as a master
Dim group As Group = diagram.Factory.CreateGroup(master)
' Attach the box to the newly created group
group.AttachProportional(subordinate, 0, 100, 100, 120)

// Don't forget that in order to use MindFusion.Diagramming
// as a target of a drag-and-drop operation
// you need to explicitly specify so
diagramView.AllowDrop = true;

' Don't forget that in order to use MindFusion.Diagramming
' as a target of a drag-and-drop operation
' you need to explicitly specify so
diagramView.AllowDrop = True

// This sample illustrates how to define
// your own node shapes via the Shape class
// Create a new shape objects
Shape shape = new Shape(
new ElementTemplate[]
{
new ArcTemplate(0, 0, 100, 100, 0, 360)
},
new ElementTemplate[]
{
new ArcTemplate(25, 30, 15, 15, 180, 180),
new ArcTemplate(60, 30, 15, 15, 180, 180),
new ArcTemplate(30, 60, 40, 15, 0, 180)
},
null,
System.Drawing.Drawing2D.FillMode.Winding,
"Happy");
// Create a node and assign the shape to it
ShapeNode node = diagram.Factory.CreateShapeNode(10, 10, 30, 20);
node.Shape = Shape.FromId("Happy");

' This sample illustrates how to define
' your own node shapes via the Shape class
' Create a new shape objects
Dim shape As New Shape( _
New ElementTemplate() _
{ _
New ArcTemplate(0, 0, 100, 100, 0, 360) _
}, _
New ElementTemplate() _
{ _
New ArcTemplate(25, 30, 15, 15, 180, 180), _
New ArcTemplate(60, 30, 15, 15, 180, 180), _
New ArcTemplate(30, 60, 40, 15, 0, 180) _
}, _
Nothing, _
System.Drawing.Drawing2D.FillMode.Winding, _
"Happy")
' Create a node and assign the shape to it
Dim node As ShapeNode = diagram.Factory.CreateShapeNode(10, 10, 30, 20)
node.Shape = Shape.FromId("Happy")

// This sample demonstrates a way to implement
// visual effects using custom drawing
// Create a custom-drawn ShapeNode
ShapeNode box = diagram.Factory.CreateShapeNode(10, 10, 30, 30);
box.CustomDraw = CustomDraw.Additional;
// Associate event handler
diagram.DrawNode += OnDrawNode;
// ...
private void OnDrawNode(object sender, DrawNodeEventArgs e)
{
RectangleF rc = e.Bounds;
rc.X += 5;
rc.Width -= 5;
for (int i = 0; i < 10; i++)
{
System.Drawing.Brush brush =
new System.Drawing.SolidBrush(
Color.FromArgb(255 - i * 25, Color.Red));
System.Drawing.Pen pen =
new System.Drawing.Pen(
Color.FromArgb((255 - i * 25) / 2, Color.Black), 0.9f);
e.Graphics.FillEllipse(brush, rc);
e.Graphics.DrawEllipse(pen, rc);
rc.Offset(-0.5f, 0);
brush.Dispose();
pen.Dispose();
}
}

' This sample demonstrates a way to implement
' visual effects using custom drawing
' Create a custom-drawn ShapeNode
Dim box As ShapeNode = diagram.Factory.CreateShapeNode(10, 10, 30, 30)
box.CustomDraw = CustomDraw.Additional
' Associate event handler
AddHandler diagram.DrawNode, AddressOf OnDrawNode
' ...
Private Sub OnDrawNode(sender As Object, e As DrawNodeEventArgs)
Dim rc As RectangleF = e.Bounds
rc.X += 5
rc.Width -= 5
For i As Integer = 0 to 10
Dim brush As New System.Drawing.SolidBrush( _
Color.FromArgb(255 - i * 25, Color.Red))
Dim pen As New System.Drawing.Pen( _
Color.FromArgb((255 - i * 25) / 2, Color.Black), 0.9f)
e.Graphics.FillEllipse(brush, rc)
e.Graphics.DrawEllipse(pen, rc)
rc.Offset(-0.5f, 0)
brush.Dispose()
pen.Dispose()
Next
End Sub

// This sample demonstrates how to set
// transparent icons on MindFusion.Diagramming nodes
// Create new ShapeNode
ShapeNode node = diagram.Factory.CreateShapeNode(10, 10, 12, 12);
// Assign one of the standard system icons to the node
System.IO.MemoryStream s = new System.IO.MemoryStream();
SystemIcons.Information.Save(s);
node.Image = Image.FromStream(s);
node.ImageAlign = MindFusion.Drawing.ImageAlign.Stretch;
// Make the node transparent,
// so that only the icon is visible
node.Transparent = true;

' This sample demonstrates how to set
' transparent icons on MindFusion.Diagramming nodes
' Create new ShapeNode
Dim node As ShapeNode = diagram.Factory.CreateShapeNode(10, 10, 12, 12)
' Assign one of the standard system icons to the node
Dim s As New System.IO.MemoryStream()
SystemIcons.Information.Save(s)
node.Image = Image.FromStream(s)
node.ImageAlign = MindFusion.Drawing.ImageAlign.Stretch
' Make the node transparent,
' so that only the icon is visible
node.Transparent = True

// This sample demonstrates how to override
// the standard MindFusion.Diagramming item drawing
// behavior through event handling
// Disable interactive node creation
diagramView.Behavior = Behavior.Modify;
// Then create new event handler and associate
// it with the Diagram.DoubleClicked event
diagram.DoubleClicked += OnDoubleClicked;
// Doing so we would create new nodes
// when the document is double-clicked
// rather than when the user click-and-drags
// with the mouse
// ...
// Double-click event handler
private void OnDoubleClicked(object sender, DiagramEventArgs e)
{
// Create new ShapeNode
diagram.Factory.CreateShapeNode(e.MousePosition.X - 5,
e.MousePosition.Y - 5, 10, 10);
}

' This sample demonstrates how to override
' the standard MindFusion.Diagramming item drawing
' behavior through event handling
' Disable interactive node creation
diagramView.Behavior = Behavior.Modify
' Then create new event handler and associate
' it with the Diagram.DoubleClicked event
AddHandler diagram.DoubleClicked, AddressOf OnDoubleClicked
' Doing so we would create new nodes
' when the document is double-clicked
' rather than when the user click-and-drags
' with the mouse
' ...
' Double-click event handler
Private Sub OnDoubleClicked(sender As Object, e As DiagramEventArgs)
' Create new ShapeNode
diagram.Factory.CreateShapeNode(e.MousePosition.X - 5, _
e.MousePosition.Y - 5, 10, 10)
End Sub

// The sample illustrates the method used
// in this step to visualize XML contents
// Load the XML document, assuming that
// the path is a valid path to a XML file
System.Xml.XmlDocument doc = new System.Xml.XmlDocument();
doc.Load(path);
// Set the link style
diagram.LinkShape = LinkShape.Cascading;
diagram.LinkSegments = 2;
diagram.LinkCascadeOrientation = MindFusion.Diagramming.Orientation.Vertical;
// Process the XML document
int yIndent = 10;
Process(10, ref yIndent, null, doc);
// ...
private void Process(int xIndent, ref int yIndent,
ShapeNode parent, System.Xml.XmlNode node)
{
if (node == null)
return;
// Create a child node for this node
ShapeNode childNode = diagram.Factory.CreateShapeNode(xIndent, yIndent, 20, 5);
if (node.NodeType == System.Xml.XmlNodeType.Text)
{
childNode.Text = node.Value.ToString();
childNode.Brush = new MindFusion.Drawing.SolidBrush(Color.LightYellow);
}
else
{
childNode.Text = node.Name;
childNode.Brush = new MindFusion.Drawing.SolidBrush(Color.BurlyWood);
}
yIndent += 8;
// Link this child node with its parent
if (parent != null)
diagram.Factory.CreateDiagramLink(parent, childNode);
// Process the children
foreach (System.Xml.XmlNode child in node.ChildNodes)
Process(xIndent + 25, ref yIndent, childNode, child);
}

' The sample illustrates the method used
' in this step to visualize XML contents
' Load the XML document, assuming that
' the path is a valid path to a XML file
Dim doc As New System.Xml.XmlDocument()
doc.Load(path)
' Set the link style
diagram.LinkShape = LinkShape.Cascading
diagram.LinkSegments = 2
diagram.LinkCascadeOrientation = MindFusion.Diagramming.Orientation.Vertical
' Process the XML document
Dim yIndent As Integer = 10
Process(10, yIndent, Nothing, doc)
' ...
Private Sub Process(xIndent As Integer, ByRef yIndent As Integer, _
parent As ShapeNode, node As System.Xml.XmlNode)
If node Is Nothing Then
Return
End If
' Create a child node for this node
Dim childNode As ShapeNode = diagram.Factory.CreateShapeNode(xIndent, yIndent, 20, 5)
If node.NodeType = System.Xml.XmlNodeType.Text Then
childNode.Text = node.Value.ToString()
childNode.Brush = New MindFusion.Drawing.SolidBrush(Color.LightYellow)
Else
childNode.Text = node.Name
childNode.Brush = New MindFusion.Drawing.SolidBrush(Color.BurlyWood)
End If
yIndent += 8
' Link this child node with its parent
If Not parent Is Nothing Then
diagram.Factory.CreateDiagramLink(parent, childNode)
End If
' Process the children
For Each child As System.Xml.XmlNode In node.ChildNodes
Process(xIndent + 25, yIndent, childNode, child)
Next
End Sub

// The following code illustrates how to load components from XML and how
// display the components in a Diagram using CompositeNode.
CompositeNode node = new CompositeNode(diagram);
node.Components.Add(XmlLoader.Load("<Button Content=\"Hello!\" Clicked=\"OnButtonClicked\" />", this));
node.Bounds = new RectangleF(10, 10, 40, 20);
diagram.Nodes.Add(node);
// ... more initialization ...
// Custom drawing event handler
private void OnButtonClicked(object sender, EventArgs e)
{
MessageBox.Show("Click!");
}

' The following code illustrates how to load components from XML and how
' display the components in a Diagram using CompositeNode.
Dim node As New CompositeNode(diagram)
node.Components.Add(XmlLoader.Load("<Button Content=""Hello!"" Clicked=""OnButtonClicked"" />", Me))
node.Bounds = New RectangleF(10, 10, 40, 20)
diagram.Nodes.Add(node)
' ... more initialization ...
' Custom drawing event handler
Private Sub OnButtonClicked(sender As Object, e As EventArgs)
MessageBox.Show("Click!")
End Sub