dev 的NavBarControl动态菜单

 private void InitMunu()
        {
            navBarControl.Items.Clear();
            navBarControl.Groups.Clear();
            navBarControl.SmallImages = this.imageTool;//dev  自带图标才会有用
            var data = CreateMunu();
            int i = 0;
            foreach (var nbg in data.Where(it => it.PID == -1))
            {
                NavBarGroup navBarGroup1 = new NavBarGroup();
                navBarGroup1.Appearance.Font = new System.Drawing.Font("微软雅黑", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
                navBarGroup1.Appearance.Options.UseFont = true;
                navBarGroup1.TopVisibleLinkIndex = i;
                navBarGroup1.Caption = nbg.FunctionName;
                //navBarGroup1.Name = "客户管理";
                navBarGroup1.SmallImageIndex = nbg.SmallImageIndex;
                if (i == 0)
                    navBarGroup1.Expanded = true;
                foreach (var nbi in data.Where(it => it.PID == nbg.ID))
                {
                    NavBarItem Item = new NavBarItem();
                    Item.Appearance.Font = new System.Drawing.Font("微软雅黑", 10.5F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
                    Item.Caption = nbi.FunctionName;
                    //Item.Name = "区本管理Item";
                    Item.SmallImageIndex = nbi.SmallImageIndex;//图标下标
                    Item.Tag = nbi.FunctionKey;
                    Item.Appearance.Options.UseFont = true;
                    Item.LinkClicked += new DevExpress.XtraNavBar.NavBarLinkEventHandler(Item_LinkClicked);
                    navBarGroup1.ItemLinks.Add(Item);//
                    navBarControl.Items.Add(Item);//dev 自带图标才会生效
                }
                navBarControl.Groups.Add(navBarGroup1);
                i++;
            }
        }
        //事件
        private void Item_LinkClicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
        {
            NavBarItem Item = (NavBarItem)sender;
            if (!string.IsNullOrEmpty(Item.Tag.ToString()))
            {
                var typeFullNames = Item.Tag.ToString().Split(',');
                foreach (var typeFullName in typeFullNames)
                {
                    var type = GetFrom(typeFullName);//反射窗体类型
                    if (type != null)
                    {
                        type.Text = Item.Caption;
                        ShowMdiForm(type);
                    }
                }
            }
        }

 

posted @ 2021-11-01 09:06  世人皆萌  阅读(470)  评论(0编辑  收藏  举报