问题描述
publicvoidAddPages(){//约定菜单共有3级别,第一级为大类,第二级为模块,第三级为菜单//添加第一级List<MenuNodeInfo>menuList=getinfo();if(menuList.Count==0)return;inti=0;foreach(MenuNodeInfofirstInfoinmenuList){//添加一级菜单RibbonTabItemtab=newRibbonTabItem();tab.Text=firstInfo.Name;tab.Name=firstInfo.Id;RibbonPanelrp=newRibbonPanel();tab.Panel=rp;rp.Dock=DockStyle.Fill;control.Controls.Add(rp);control.Items.Add(tab,i);if(firstInfo.Children.Count==0)continue;foreach(MenuNodeInfosecondInfoinfirstInfo.Children){RibbonBarrb=newRibbonBar();rb.Text=secondInfo.Name;if(secondInfo.Children.Count==0)continue;intj=0;foreach(MenuNodeInfothirdInfoinsecondInfo.Children){ButtonItembi=newButtonItem();bi.Name=thirdInfo.Id;bi.Text=thirdInfo.Name;bi.Image=thirdInfo.Image;bi.ImagePosition=eImagePosition.Top;bi.Command=com;rb.Items.Add(bi,j);j++;}rp.Controls.Add(rb);}i++;}}publicList<MenuNodeInfo>getinfo(){List<MenuNodeInfo>list=newList<MenuNodeInfo>();#region//第3级#region00MenuNodeInfoinfo_001=newMenuNodeInfo();info_001.Id="A1";info_001.Name="A1";info_001.Image=Properties.Resources.NewDocument;MenuNodeInfoinfo_002=newMenuNodeInfo();info_002.Id="A2";info_002.Name="A2";info_002.Image=Properties.Resources.NewDocument;//第二级List<MenuNodeInfo>list_00=newList<MenuNodeInfo>();list_00.Add(info_001);list_00.Add(info_002);MenuNodeInfoinfo_00=newMenuNodeInfo();info_00.Id="A";info_00.Name="A";info_00.Image=Properties.Resources.NewDocument;info_00.Children=list_00;#endregion#region01//第3级MenuNodeInfoinfo_010=newMenuNodeInfo();info_010.Id="B1";info_010.Name="B1";info_010.Image=Properties.Resources.NewDocument;MenuNodeInfoinfo_011=newMenuNodeInfo();info_011.Id="B2";info_011.Name="B2";info_011.Image=Properties.Resources.NewDocument;//第二级List<MenuNodeInfo>list_01=newList<MenuNodeInfo>();list_01.Add(info_010);list_01.Add(info_011);MenuNodeInfoinfo_01=newMenuNodeInfo();info_01.Id="B";info_01.Name="B";info_01.Image=Properties.Resources.NewDocument;info_01.Children=list_01;#endregion#region02//第3级MenuNodeInfoinfo_020=newMenuNodeInfo();info_020.Id="C1";info_020.Name="C1";info_020.Image=Properties.Resources.NewDocument;MenuNodeInfoinfo_021=newMenuNodeInfo();info_021.Id="C2";info_021.Name="C2";info_021.Image=Properties.Resources.NewDocument;MenuNodeInfoinfo_022=newMenuNodeInfo();info_022.Id="C3";info_022.Name="C3";info_022.Image=Properties.Resources.NewDocument;//第二级List<MenuNodeInfo>list_02=newList<MenuNodeInfo>();list_02.Add(info_020);list_02.Add(info_021);list_02.Add(info_022);MenuNodeInfoinfo_02=newMenuNodeInfo();info_02.Id="C";info_02.Name="C";info_02.Image=Properties.Resources.NewDocument;info_02.Children=list_02;#endregion#region03//第3级MenuNodeInfoinfo_030=newMenuNodeInfo();info_030.Id="D1";info_030.Name="D1";info_030.Image=Properties.Resources.NewDocument;MenuNodeInfoinfo_031=newMenuNodeInfo();info_031.Id="D2";info_031.Name="D2";info_031.Image=Properties.Resources.NewDocument;//第二级List<MenuNodeInfo>list_03=newList<MenuNodeInfo>();list_03.Add(info_030);list_03.Add(info_031);MenuNodeInfoinfo_03=newMenuNodeInfo();info_03.Id="D";info_03.Name="D";info_03.Image=Properties.Resources.NewDocument;info_03.Children=list_03;#endregion//第一级List<MenuNodeInfo>list_0=newList<MenuNodeInfo>();list_0.Add(info_03);//Dlist_0.Add(info_02);//Clist_0.Add(info_01);//Blist_0.Add(info_00);//AMenuNodeInfoinfo_0=newMenuNodeInfo();info_0.Id="0";info_0.Name="菜单";info_0.Image=Properties.Resources.NewDocument;info_0.Children=list_0;#endregionlist.Add(info_0);returnlist;}
我想让他按照ABCD排序不是这样乱的排序有没有人知道办法的?
解决方案
解决方案二:
你先看下getinfo()这个方法返回的list顺序,然后再看AddPages()方法里面是否按照顺序添加的。
解决方案三:
是按照顺序添加的代码已经贴出但是出来的不是按照顺序出来的
解决方案四:
没有人吗自己顶起来
解决方案五:
好像有个visibleIndex属性找找看
解决方案六:
intpageCount=4;intzuCount=9;//页签数量和组数量for(intx=0;x<pageCount;x++){RibbonPanelpage=newRibbonPanel(){Dock=System.Windows.Forms.DockStyle.Fill,Padding=newSystem.Windows.Forms.Padding(3,0,3,3)};//页签RibbonTabItempageTitle=newRibbonTabItem(){Panel=page,Name="tab"+x.ToString(),Text="页签"+x.ToString()};//页标题ribbonControl1.Controls.Add(page);ribbonControl1.Items.AddRange(newBaseItem[]{pageTitle});pageTitle.Checked=x==0?true:false;Control[]zuList=newRibbonBar[zuCount];//生成组for(inty=0;y<zuCount;y++){RibbonBarzu=newRibbonBar(){Dock=System.Windows.Forms.DockStyle.Left,Name="zu"+x.ToString(),Text=""+x.ToString()+""+y.ToString()};zu.Location=newSystem.Drawing.Point(y*100+3,0);zu.Size=newSystem.Drawing.Size(200,95);for(intz=0;z<2;z++){ButtonItembtn=newButtonItem(){Name=Text="btn"+x.ToString()+y.ToString()+z.ToString(),Text=""+x.ToString()+y.ToString()+z.ToString()};//生成按钮zu.Items.Insert(z,btn);}zuList[y]=zu;}page.Controls.AddRange(zuList);}