DEV控件 navbarControl 动态添加xml文件

来源:互联网 发布:易企秀源码 编辑:程序博客网 时间:2024/05/16 02:25

navbarControl 是一个很强大的控件,当初在用的时候网上很少这样的例子。

所以今天记录一下,当做再次学习。




 private void GetXmlToNavBar()
        {
            string image = ""; //xml图片路径,如果为空则不显示图片
            try
            {
                XmlDocument doc = new XmlDocument();
                doc.Load(fileName);


                foreach (XmlNode nd in doc.DocumentElement.ChildNodes)
                {  // nd 遍历所有docctrl节点
                    string version = nd.Attributes["name"].Value.ToString();
                    NavBarGroup nbg = new NavBarGroup();
                    nbg.Caption = version;
                    nbcLeft.Groups.Add(nbg);
                    if (nd.HasChildNodes)
                    {
                        foreach (XmlNode n in nd.ChildNodes)
                        {  // n 遍历所有doc和ctrl节点
                            string stype = n.Attributes["name"].Value.ToString();
                            string versions = n.Attributes["name"].Value.ToString();
                            
                            image = n.Attributes["image"].Value.ToString();
                            NavBarItem nbi = new NavBarItem();
                            if (image != "")
                            {
                                nbi.SmallImage = Image.FromFile(Application.StartupPath + "\\" + image);
                            }
                            nbi.Caption = versions;
                            nbg.ItemLinks.Add(nbi);  // 节点的值
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }




配上xml文件格式:

<?xml version="1.0" encoding="GB2312"?>


<root>
<rights name="常用功能">
<xml name="功能一" code="stockmarket" image="Images\Actions\Group2_16x16.png"></xml>
<xml name="功能二" code="sales" image="Images\Actions\Group2_16x16.png"></xml>
<xml name="功能三" code="servcice" image=""></xml>
</rights>
<rights name="策略管理">
<xml name="策略维护" code="stockmarket" image="Images\Actions\Group2_16x16.png"></xml>
<xml name="所有策略" code="sales" image="Images\Actions\Group2_16x16.png"></xml>
<xml name="策略墙" code="servcice" image=""></xml>
</rights>
<rights name="模拟交易">
<xml name="模拟组合维护" code="so_mana" image="Images\Actions\Group2_16x16.png"></xml>
<xml name="单行" code="so_list" image="Images\Actions\Group2_16x16.png"></xml>
<xml name="批行" code="so_audit_list" image="Images\Actions\Group2_16x16.png"></xml>
<xml name="自行" code="so_ur_sour_list" image=""></xml>
<xml name="风险控制" code="so_ur" image="Images\Actions\Group2_16x16.png"></xml>
</rights> 
<rights name="实易">
<xml name="组护" code="so_mana" image="Images\Actions\Group2_16x16.png"></xml>
<xml name="单行" code="so_list" image="Images\Actions\Group2_16x16.png"></xml>
<xml name="批入" code="so_audit_list" image="Images\Actions\Group2_16x16.png"></xml>
<xml name="自行" code="so_audit" image="Images\Actions\Group2_16x16.png"></xml>
<xml name="风险控制" code="audit_list" image="Images\Actions\Group2_16x16.png"></xml>
</rights>
<rights name = "日终结算">
<xml name="盘后数据导入" code="QT.Clearing.UI.dll,QT.Clearing.UI.ClearingMainForm" image="Images\Actions\Group2_16x16.png"></xml>
<xml name="批量指令导入" code="so_list" image=""></xml>
</rights>
<rights name = "系统管理">
<xml name="产品" code="QT.SubPages.dll,QT.SubPages.FundProductsForm" image="Images\Actions\Group2_16x16.png"></xml>
<xml name="信息" code="asdasdasdasdasds.dll,asdasdasdasdasds.Form1" image="Images\Actions\Group2_16x16.png"></xml>
<xml name="库" code="so_audit_list" image="Images\Actions\Group2_16x16.png"></xml>
</rights>
</root>


0 0
原创粉丝点击