c#动态读取菜单栏,并显示
各们好,看来现在不少的软件的菜单的生成都是从数据库中读取的,根据不同的工作人员的权限以及职务。主菜单,子菜单都是从数据库中读取并生成。请问这种架构是如何实现的呢?先谢谢了。 --------------------编程问答-------------------- 递归读取菜单,然后通过代码生成菜单
/// <summary>
/// 加载菜单
/// </summary>
private void LoadMenu()
{
IList<MenuItemInfo> list = MenuManager.GetMenu(this);
foreach (MenuItemInfo menu in list)
{
ToolStripMenuItem item = new ToolStripMenuItem();
item.Size = new System.Drawing.Size(29, 20);
item.Text = menu.Name;
this.mainMenu.Items.Add(item);
RecursionMenu(item, menu);
}
}
private void RecursionMenu(ToolStripMenuItem item, MenuItemInfo menu)
{
foreach (MenuItemInfo subMenu in menu.SubMenuList)
{
ToolStripMenuItem subItem = new ToolStripMenuItem();
subItem.Size = new System.Drawing.Size(29, 20);
subItem.Text = subMenu.Name;
if (subMenu.IsLeaf)
{
subItem.Tag = subMenu.Directory;
subItem.Click += new EventHandler(ToolStripMenuItem_Click);
}
item.DropDownItems.Add(subItem);
if (subMenu.SubMenuList.Count != 0)
{
RecursionMenu(subItem, subMenu);
}
}
} --------------------编程问答--------------------
补充:.NET技术 , C#