因项目需要要实现类似jquery的Tab效果,所以要用到xtraTabbedMdiManager控件
使用xtraTabbedMdiManager一般配合navBarControl(上期已写过)
在工具箱xtraTabbedMdiManager拖到界面,在属性中将MdiParent设置成(无)
大概代码:
xtraTabbedMdiManager1.MdiParent = this; //设置控件的父表单.. XtraForm1 frm = new XtraForm1(); //定义一个form1窗体 frm.MdiParent = this; //设置新建窗体的父表单为当前活动窗口 xtraTabbedMdiManager1.SelectedPage = xtraTabbedMdiManager1.Pages[frm]; //使得标签的选择为当前新建的窗口 this.xtraTabbedMdiManager1.ClosePageButtonShowMode = DevExpress.XtraTab.ClosePageButtonShowMode.InAllTabPagesAndTabControlHeader; //设置标签后面添加删除按钮 , 多个标签只需要设置一次..
具体代码:
首先增加navBarControl控件
this.navBarControl1.Groups.Clear(); string strFrmName = "select top 10 ModuleCode,ModuleName,AssemblyName,FormName from [000].tbModule where AssemblyName='KidsServer'"; DataTable dtFrmName = DBHelper.SQLDBHelper.GetDataTable(strFrmName, DBHelper.SQLDBHelper.conStringHQ); NavBarGroup _navBarGroup = new NavBarGroup(); _navBarGroup.Name = "_navBarGroup"; _navBarGroup.Caption = "财务管理"; foreach (DataRow dr in dtFrmName.Rows) { NavBarItem _navBarItem = new NavBarItem(); _navBarItem.Name = dr["ModuleCode"].ToString(); _navBarItem.Caption = dr["ModuleName"].ToString(); string strFilePath = System.IO.Directory.GetCurrentDirectory() + @"imagesadd.png"; // _navBarItem.LargeImage = Image.FromFile(strFilePath);//这里一直无法显示图片,不知道是不是我写错了还是什么 _navBarItem.LargeImageIndex = 0; _navBarItem.LinkClicked += new NavBarLinkEventHandler(_navBarItem_LinkClicked); _navBarGroup.ItemLinks.Add(_navBarItem); } navBarControl1.Groups.Add(_navBarGroup); _navBarGroup.Expanded = true;
NavBarItem事件(实现xtraTabbedMdiManager控件效果):
void _navBarItem_LinkClicked(object sender, NavBarLinkEventArgs e) { NavBarItem _navBarItem = (NavBarItem)sender; string strFrmName = string.Format("select ModuleCode,ModuleName,AssemblyName,FormName from [000].tbModule where ModuleCode = '{0}'", _navBarItem.Name); DataTable dtFrmName = DBHelper.SQLDBHelper.GetDataTable(strFrmName, DBHelper.SQLDBHelper.conStringHQ); string pathDll = Application.StartupPath + @"" + dtFrmName.Rows[0]["AssemblyName"].ToString() + ".dll"; Assembly _assembly = Assembly.LoadFrom(pathDll); //定义一个"类型信息"的对象. Type t = _assembly.GetType(dtFrmName.Rows[0]["FormName"].ToString(), false, true);//就是这里,我获取了dll的窗体名称 ConstructorInfo cont = t.GetConstructor(new Type[0]); XtraForm xf = (XtraForm)cont.Invoke(new object[0]); //拖动xtraTabbedManager到窗体中,在属性中将MdiParent设置成(无)... xtraTabbedMdiManager1.MdiParent = this; //设置控件的父表单.. xf.MdiParent = this; //设置新建窗体的父表单为当前活动窗口 xf.Show(); //以非模式窗口方式打开 xtraTabbedMdiManager1.SelectedPage = xtraTabbedMdiManager1.Pages[xf]; //使得标签的选择为当前新建的窗口 this.xtraTabbedMdiManager1.ClosePageButtonShowMode = DevExpress.XtraTab.ClosePageButtonShowMode.InAllTabPagesAndTabControlHeader; //设置标签后面添加删除按钮 , 多个标签只需要设置一次.. }
效果如下: