private void GetMenuItem(MenuItem item, MenuInfoModel model) { var query = from menu in CacheInfo.listMenuInfoModel() where (menu.MenuParentId == model.MenuId && menu.MenuUse == true) select menu; if (query == null || query.Count() == 0) { return; } int intNo = 0; foreach (var ci in query) { string strtext = ci.MenuName; MenuItem mMenuItem; if (strtext == "-") { //如果是分隔符-,那么不显示顺序 mMenuItem = new MenuItem(strtext); } else { intNo++; mMenuItem = new MenuItem(ChangeNo(intNo) + "." + strtext); } mMenuItem.Tag = ci; mMenuItem.Click += new System.EventHandler(this.ItemClick); GetMenuItem(mMenuItem, ci); item.MenuItems.Add(mMenuItem); } }
//List<MenuInfoModel> listMenuInfo = new List<MenuInfoModel>(); #region MainMenu private void InitMainMenu() { MainMenu theMenu = new MainMenu(); //listMenuInfo = new MenuInfoBLL().GetModelList(""); if (CacheInfo.listMenuInfoModel() == null || CacheInfo.listMenuInfoModel().Count == 0) { return; } var query = from menu in CacheInfo.listMenuInfoModel() where (menu.MenuParentId == 0 && menu.MenuUse == true) select menu; if (query == null || query.Count() == 0) { return; } foreach (var ci in query) { MenuItem item = new MenuItem(ci.MenuName); item.Tag = ci; GetMenuItem(item, ci); theMenu.MenuItems.Add(item); } this.Menu = theMenu; }
private void GetMenuStripItem(ToolStripMenuItem item, MenuInfoModel model) { var query = from menu in CacheInfo.listMenuInfoModel() where (menu.MenuParentId == model.MenuId && menu.MenuUse == true) select menu; if (query == null || query.Count() == 0) { return; } int intNo = 0; foreach (var ci in query) { string strtext = ci.MenuName; ToolStripMenuItem itemDetail = new ToolStripMenuItem(); if (strtext == "-") { //如果是分隔符-,那么不显示顺序 itemDetail = new ToolStripMenuItem(strtext); ToolStripSeparator toolStripSeparator = new ToolStripSeparator(); item.DropDownItems.Add(toolStripSeparator); } else { intNo++; itemDetail = new ToolStripMenuItem(ChangeNo(intNo) + "." + strtext); itemDetail.Tag = ci; itemDetail.Click += new System.EventHandler(this.ItemDetailClick); GetMenuStripItem(itemDetail, ci); item.DropDownItems.Add(itemDetail); } } }
private void InitMenuStrip() { try { //listMenuInfo = new MenuInfoBLL().GetModelList(""); if (CacheInfo.listMenuInfoModel() == null || CacheInfo.listMenuInfoModel().Count == 0) { return; } var query = from menu in CacheInfo.listMenuInfoModel() where (menu.MenuParentId == 0 && menu.MenuUse == true) select menu; if (query == null || query.Count() == 0) { return; } foreach (var ci in query) { ToolStripMenuItem item = new ToolStripMenuItem(ci.MenuName); item.Tag = ci; GetMenuStripItem(item, ci); this.menuStrip.Items.Add(item); } } catch (Exception ex) { MessageBox.Show("初始化菜单出错:" + ex.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void InitBarManager() { //string[] strMenus = { "系统管理", "会员管理", "财务管理", "报表管理", "基础资料", "货品管理", "客户管理", "物流管理" }; //Utils.ImageCollection largeImgs; var query = CacheInfo.listMenuInfoModel().Where(p => p.MenuBig == true).ToList(); if (query == null || query.Count() == 0) { return; } string imagePath = Application.StartupPath + "\\TempImage"; int imgindex = 0; string fileName = string.Empty; foreach (var model in query) { if (model.MenuBigImage == null) { return; } //添加图标到资源文件 fileName = string.Format("{0}.png", model.MenuFrmName); ImageTools.CreateImage(imagePath, fileName, model.MenuBigImage); System.Resources.IResourceWriter rw = new System.Resources.ResourceWriter("Resource.resx"); rw.AddResource(model.MenuFrmName, (Image)Image.FromStream(new MemoryStream(model.MenuBigImage)).Clone());//Image.FromFile( imagePath + "\\" + fileName) rw.Close(); //把资源文件中的图像添加到largeImgs中 this.largeImgs.Images.Add((Image)Image.FromStream(new MemoryStream(model.MenuBigImage)).Clone(), model.MenuFrmName); //this.largeImgs.Images.SetKeyName(imgindex, fileName); //创建大图标菜单 DevExpress.XtraBars.BarLargeButtonItem barLargeItem = new DevExpress.XtraBars.BarLargeButtonItem(barMain, model.MenuName); barLargeItem.LargeGlyph = largeImgs.Images[imgindex];//也可以设置 barLargeItem.LargeImageIndex,但是效果不是很好,可以试试 barLargeItem.Hint = model.MenuName; barLargeItem.Tag = model.MenuName; barTop.LinksPersistInfo.Add(new DevExpress.XtraBars.LinkPersistInfo(barLargeItem, true)); barMain.Items.Add(barLargeItem); imgindex++; } }