1.在“引用”中添加DevExpress.XtraBars和DexExpress.XtraNavBar程序集
2.往工具栏拖出DockManager控件,点击右上角的小三角,再点击“customize”,最后点击“New”,新建一个DockPanel控件
3.往工具栏拖出NavBarControl控件放入DockPanel控件里面,
另附:
DockPanel属性设置:
Options -》ShowCloseButton:显示关闭按钮
NavBarControl属性设置:
OptionsNavPane -》 ShowExpandButton:显示展开按钮
-》 ShowOverFlowButton:显示漂浮按钮
效果图:
4.在里面添加TreeList控件
private void Frm_Mains_Load(object sender, EventArgs e) { InitMenu(); } public void InitMenu() { PSContext _db = new PSContext(); this.navBarMenu.Groups.Clear(); //添加组 NavBarGroup nbg = new NavBarGroup(); nbg.Name = "group1"; nbg.Caption = "管理业务"; nbg.GroupStyle = NavBarGroupStyle.ControlContainer; this.navBarMenu.Groups.Add(nbg); //添加控制面板 NavBarGroupControlContainer nbgcc = new NavBarGroupControlContainer(); nbg.ControlContainer = nbgcc; //添加树 TreeList tl = new TreeList(); tl.SelectImageList = this.imageCollection1; #region TreeList属性设置 tl.BackColor = Color.White; tl.Dock = DockStyle.Fill; tl.LookAndFeel.UseWindowsXPTheme = true; tl.LookAndFeel.UseDefaultLookAndFeel = false; tl.OptionsSelection.EnableAppearanceFocusedCell = true; tl.OptionsSelection.EnableAppearanceFocusedRow = false; tl.Appearance.FocusedCell.BackColor = Color.LightSteelBlue; tl.Appearance.FocusedCell.BackColor2 = Color.SteelBlue; tl.OptionsBehavior.Editable = false; tl.OptionsView.ShowColumns = false; tl.OptionsView.ShowHorzLines = false; tl.OptionsView.ShowIndentAsRowStyle = true; tl.OptionsView.ShowIndicator = false; tl.OptionsView.ShowVertLines = false; tl.OptionsView.ShowFocusedFrame = false; tl.OptionsSelection.EnableAppearanceFocusedRow = false; tl.MouseClick += MenuTree_Click; tl.FocusedNodeChanged += new DevExpress.XtraTreeList.FocusedNodeChangedEventHandler(this.treelist1_FocusedNodeChanged); #endregion //设置主父键关系 tl.KeyFieldName = "ID"; tl.ParentFieldName = "ParentID"; //添加列 TreeListColumn tlc1 = tl.Columns.Add();
tlc1.FieldName = "Name"; tlc1.Visible = true; TreeListColumn tlc2 = tl.Columns.Add(); tlc2.FieldName = "WinName"; tlc2.Visible = false; //加载数据 tl.DataSource = _db.BusinessNavs.ToList(); nbgcc.Controls.Add(tl); }