彩票走势图

流程图控件FlowChart.NET使用教程:加载分层数据

原创|使用教程|编辑:郝浩|2013-05-30 14:30:12.000|阅读 973 次

概述:本教程展示在FlowChart.NET如何从XML中加载图数据,以及创建一个对应于图节点和边的图对象。

# 慧都年终大促·界面/图表报表/文档/IDE等千款热门软控件火热促销中 >>

相关链接:

本教程展示在业务流程图控件FlowChart.NET中如何从XML中加载图数据,以及创建一个对应于图节点和边的图对象。

1、右键单击项目的上下文菜单,选择添加- >新项目,创建一个新的叫做SampleTree.xml的XML文件,并在下面的窗格中给它添加内容:

XML

<?xml version="1.0" encoding="utf-8" ?> 
<Project>
    <Activity Name="Activity 1">
        <Activity  Name="sub-activity 1">
            <Activity  Name="sub-activity 1-1" />
            <Activity  Name="sub-activity 1-2" />
        </Activity>
        <Activity  Name="sub-activity 2">
            <Activity  Name="sub-activity 2-1" />
            <Activity  Name="sub-activity 2-2" />
            <Activity  Name="sub-activity 2-3" />
        </Activity>
        <Activity  Name="sub-activity 3">
            <Activity  Name="sub-activity 3-1" />
            <Activity  Name="sub-activity 3-2" />
        </Activity>
    </Activity>
    <Activity Name="Activity 2">
        <Activity  Name="sub-activity 1">
            <Activity  Name="sub-activity 1-1" />
            <Activity  Name="sub-activity 1-2" />
            <Activity  Name="sub-activity 1-3" />
        </Activity>
        <Activity  Name="sub-activity 2">
            <Activity  Name="sub-activity 2-1" />
            <Activity  Name="sub-activity 2-2" />
        </Activity>
    </Activity>
    <Activity Name="Activity 3">
        <Activity  Name="sub-activity 1">
            <Activity  Name="sub-activity 1-1" />
            <Activity  Name="sub-activity 1-2" />
            <Activity  Name="sub-activity 1-3" />
            <Activity  Name="sub-activity 1-4" />
        </Activity>
        <Activity  Name="sub-activity 2" />
        <Activity  Name="sub-activity 3">
            <Activity  Name="sub-activity 3-1" />
            <Activity  Name="sub-activity 3-2" />
        </Activity>
    </Activity>
</Project>

2、设置文件的“创建操作”属性到“内容”,以及那设置“复制输出”到“如果更新就复制”。

3、覆盖OnLoad方法。

C#

protected override void OnLoad(EventArgs e)
{
    base.OnLoad(e);
}

Visual Basic

Protected Overrides Sub OnLoad(ByVal e As EventArgs)

    MyBase.OnLoad(e)

End Sub

4、添加以下成员到窗口类来保存默认节点大小。

C#

RectangleF nodeBounds = new RectangleF(0, 0, 24, 6);
Visual Basic 
Dim nodeBounds As New RectangleF(0, 0, 24, 6)

5、创建树的根节点,并调用CreateChildren方法构建树递归:

C#

ShapeNode root = diagram.Factory.CreateShapeNode(nodeBounds);
root.Text = "Project";
XmlDocument document = new XmlDocument();
document.Load("SampleTree.xml");
CreateChildren(root, document.SelectSingleNode("Project")); 

Visual Basic

Dim root As ShapeNode = diagram.Factory.CreateShapeNode(nodeBounds)
root.Text = "Project"
Dim document As New XmlDocument()
document.Load("SampleTree.xml")
CreateChildren(root, document.SelectSingleNode("Project"))

6、如下定义CreateChildren,作为父节点和父XML元素的参数,迭代子XML元素来构建新的层级,通过调用CreateShapeNode和CreateDiagramLink创建一个相应的图项目。

C#

private void CreateChildren(DiagramNode parentDiagNode, XmlNode parentXmlNode)
{
    foreach (XmlElement element in parentXmlNode.SelectNodes("Activity"))
    {
        ShapeNode node = diagram.Factory.CreateShapeNode(nodeBounds);
        node.Text = element.GetAttribute("Name");
        diagram.Factory.CreateDiagramLink(parentDiagNode, node);
        CreateChildren(node, element);
    }
}

Visual Basic

Private Sub CreateChildren(ByVal parentDiagNode As DiagramNode, ByVal parentXmlNode As XmlNode)

    For Each element As XmlElement In parentXmlNode.SelectNodes("Activity")

        Dim node As ShapeNode = diagram.Factory.CreateShapeNode(nodeBounds)
        node.Text = element.GetAttribute("Name")
        diagram.Factory.CreateDiagramLink(parentDiagNode, node)
        CreateChildren(node, element)

    Next

End Sub

7、使用TreeLayout布局来安排图,添加下面的代码到OnLoad覆盖。

C#

TreeLayout layout = new TreeLayout();
layout.Type = TreeLayoutType.Cascading;
layout.Direction = TreeLayoutDirections.LeftToRight;
layout.LinkStyle = TreeLayoutLinkType.Cascading2;
layout.NodeDistance = 3;
layout.LevelDistance = -8; // let horizontal positions overlap
layout.Arrange(diagram);
Visual Basic 
Dim layout As New TreeLayout()
layout.Type = TreeLayoutType.Cascading
layout.Direction = TreeLayoutDirections.LeftToRight
layout.LinkStyle = TreeLayoutLinkType.Cascading2
layout.NodeDistance = 3
layout.LevelDistance = -8
' let horizontal positions overlap
layout.Arrange(diagram)

8、建立并运行该项目。如果一切顺利,你应该看到这种表示的层次结构:

流程图控件FlowChart.NET使用教程:加载分层数据


标签:

本站文章除注明转载外,均为本站原创或翻译。欢迎任何形式的转载,但请务必注明出处、不得修改原文相关链接,如果存在内容上的异议请邮件反馈至chenjj@capbkgr.cn

文章转载自:慧都控件

为你推荐

  • 推荐视频
  • 推荐活动
  • 推荐产品
  • 推荐文章
  • 慧都慧问
扫码咨询


添加微信 立即咨询

电话咨询

客服热线
023-68661681

TOP