动态创建菜单,menustrip,根据权限显示菜单,控制菜单可用,反射,给窗体传值,反射对象传值,public static Object CreateInstance ( Type type, ...


None.gif using  System;
None.gif
using  System.Collections.Generic;
None.gif
using  System.ComponentModel;
None.gif
using  System.Data;
None.gif
using  System.Drawing;
None.gif
using  System.Text;
None.gif
using  System.Windows.Forms;
None.gif
using  System.IO;
None.gif
using  System.Reflection;
None.gif
using  Kimbanx.SecurityDiskSystem.FactoryTools.MenuItem;
None.gif
using  Program.BLL;
None.gif
using  Kimbanx.SecurityDiskSystem.FactoryTools.DBDAL;
None.gif
using  Program.Model;
None.gif
using  System.Threading;
None.gif
using  System.Diagnostics;
None.gif
None.gif
namespace  Kimbanx.SecurityDiskSystem.FactoryTools
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
InBlock.gif    
public partial class frmMDIMain : Form
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif        
private List<int> loginUserAuthIDList;
InBlock.gif        
public frmMDIMain()
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            InitializeComponent();
InBlock.gif
ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif        
private void ExitSysMenu_Click(object sender, EventArgs e)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            Application.Exit();
ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif        
private void checkDisk_Click(object sender, EventArgs e)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            CheckDiskForm checkDiskForm 
= new CheckDiskForm();
InBlock.gif            checkDiskForm.ShowDialog();
ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif        
private void reInStockDisk_Click(object sender, EventArgs e)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            ReInStockDisk reInStockDisk 
= new ReInStockDisk();
InBlock.gif            reInStockDisk.ShowDialog();
ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif        
private void createConfigMenu_Click(object sender, EventArgs e)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            CreatePolicyConfig createCfg 
= new CreatePolicyConfig(ConfigFormState.Create, "创建策略配置");
InBlock.gif            createCfg.ShowDialog();
ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif        
private void ProduceDiskMenu_Click(object sender, EventArgs e)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            ProduceDisk produceDisk 
= new ProduceDisk();
InBlock.gif            produceDisk.ShowDialog();
ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif        
private void resetDisk_Click(object sender, EventArgs e)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            ResetDiks resetDisk 
= new ResetDiks();
InBlock.gif            resetDisk.ShowDialog();
ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif        
private void ResetPersonalDisk_Click(object sender, EventArgs e)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            ResetPersonalDisk resetPersonalDisk 
= new ResetPersonalDisk();
InBlock.gif            resetPersonalDisk.ShowDialog();
ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif        
private void ImportNewCfg_Click(object sender, EventArgs e)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            ImportNewCfg importCfg 
= new ImportNewCfg();
InBlock.gif            importCfg.ShowDialog();
ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif        
private void UpdateDiskTools_Click(object sender, EventArgs e)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            UpdateDiskSoft updateDisk 
= new UpdateDiskSoft();
InBlock.gif            updateDisk.ShowDialog();
ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif        
private void viewDiskInfoMenu_Click(object sender, EventArgs e)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            ShowDiskInfo showDiskInfo 
= new ShowDiskInfo();
InBlock.gif            showDiskInfo.ShowDialog();
ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif        
private void selectConfigMenu_Click(object sender, EventArgs e)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            CreatePolicyConfig viewCfg 
= new CreatePolicyConfig(ConfigFormState.View, "查看策略配置");
InBlock.gif            viewCfg.ShowDialog();
ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif        
private void importConfigMenu_Click(object sender, EventArgs e)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            CreatePolicyConfig importCfg 
= new CreatePolicyConfig(ConfigFormState.Import, "迁入策略配置");
InBlock.gif            importCfg.ShowDialog();
ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif        
private void exCfgMenu_Click(object sender, EventArgs e)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            CreatePolicyConfig exCfg 
= new CreatePolicyConfig(ConfigFormState.Export, "迁出策略配置");
InBlock.gif            exCfg.ShowDialog();
ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif        
private void exManCenterCfgMenu_Click(object sender, EventArgs e)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            CreatePolicyConfig exManCenter 
= new CreatePolicyConfig(ConfigFormState.ExportManagementCenter, "导出管控中心策略配置(企业版)");
InBlock.gif            exManCenter.ShowDialog();
ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif        
private void ManRoleMenu_Click(object sender, EventArgs e)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            ManageRoleForm manageRoleForm 
= new ManageRoleForm();
InBlock.gif            manageRoleForm.ShowDialog();
ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif        
private void ManageUserMenu_Click(object sender, EventArgs e)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            ManSysUserForm1 manSysUserForm 
= new ManSysUserForm1();
InBlock.gif            manSysUserForm.ShowDialog();
ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif        
private void SysParaMenu_Click(object sender, EventArgs e)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            SysParaForm sysParaForm 
= new SysParaForm();
InBlock.gif            sysParaForm.ShowDialog();
ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif        
private void SysLogMenu_Click(object sender, EventArgs e)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            SelectSysLogForm1 selectSysLogForm 
= new SelectSysLogForm1();
InBlock.gif            selectSysLogForm.ShowDialog();
ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif        
private void ModifyPwdMenu_Click(object sender, EventArgs e)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            ModifyUserPwdForm1 modifyUserPasswordForm 
= new ModifyUserPwdForm1();
InBlock.gif            modifyUserPasswordForm.ShowDialog();
ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif        
private void frmMDIMain_Load(object sender, EventArgs e)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            loginUserAuthIDList 
= new List<int>();
InBlock.gif            BLLUserInRole bllUserInRole 
= new BLLUserInRole();
InBlock.gif            DataTable roleDT 
= bllUserInRole.GetRoleDataTableByUserID(Helper.Helper.Log.Opeid);
InBlock.gif            List
<int> roleIDList = new List<int>();
InBlock.gif            
foreach (DataRow row in roleDT.Rows)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                roleIDList.Add(Convert.ToInt32(row[
"RoleInfoAutoID"].ToString()));
ExpandedSubBlockEnd.gif            }

InBlock.gif            loginUserAuthIDList 
= MenuItemDAL.GetAllMenuList(roleIDList);
InBlock.gif            CreateMenu(MenuItem.MenuItem.MenuContent);
InBlock.gif            
InBlock.gif            
this.menuStrip1.Items.Add(new ToolStripMenuItem("重新登录"nullnew EventHandler(reload_Click)));
InBlock.gif            
this.menuStrip1.Items.Add(new ToolStripMenuItem("退出系统",null,new EventHandler(ExitSysMenu_Click)));
InBlock.gif            
foreach (ToolStripMenuItem item in menuStrip1.Items)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
if (item.DropDownItems.Count > 0)
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    showMenu(item);
ExpandedSubBlockEnd.gif                }

InBlock.gif
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

InBlock.gif        
private void reload_Click(object sender, EventArgs e)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
//Process process = new Process();
InBlock.gif            
//process.StartInfo.FileName = "Kimbanx.SecurityDiskSystem.FactoryTools.exe";
InBlock.gif            
//process.Start();
InBlock.gif            
//Application.Exit();
InBlock.gif            
//bool flag = false;
InBlock.gif            
//Mutex mutex = new Mutex(true, "Kimbanx.SecurityDiskSystem.FactoryTools.LoginForm", out flag);
InBlock.gif            
//if (flag)
InBlock.gif            
//{
InBlock.gif            
//    LoginForm loginForm = new LoginForm();
InBlock.gif            
//    if (loginForm.ShowDialog() == DialogResult.OK)
InBlock.gif            
//    {
InBlock.gif            
//        Application.Run(new frmMDIMain());
InBlock.gif            
//    }
InBlock.gif            
//}
InBlock.gif            
//else
InBlock.gif            
//{
InBlock.gif            
//    MessageBox.Show("已经存在运行的实例!", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
InBlock.gif            
//    Application.Exit();
InBlock.gif            
//}
ExpandedSubBlockEnd.gif
        }

InBlock.gif        
private void showMenu(ToolStripMenuItem item)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif
InBlock.gif            
for (int i = 0; i < item.DropDownItems.Count; i++)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
if (((ToolStripMenuItem) item.DropDownItems[i]).DropDownItems.Count> 0)
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    showMenu((ToolStripMenuItem)item.DropDownItems[i]);
ExpandedSubBlockEnd.gif                }

InBlock.gif                
else
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    
if (loginUserAuthIDList.Contains(Convert.ToInt32(item.DropDownItems[i].Name)))
ExpandedSubBlockStart.gifContractedSubBlock.gif                    
dot.gif{
InBlock.gif                        item.DropDownItems[i].Enabled 
= true;
ExpandedSubBlockEnd.gif                    }

InBlock.gif                    
else
ExpandedSubBlockStart.gifContractedSubBlock.gif                    
dot.gif{ item.DropDownItems[i].Enabled = false; }
ExpandedSubBlockEnd.gif                }

ExpandedSubBlockEnd.gif            }

InBlock.gif
ExpandedSubBlockEnd.gif        }

ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//**/
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// 动态创建菜单
ExpandedSubBlockEnd.gif        
/// </summary>

InBlock.gif        private void CreateMenu(string menuContent)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
//定义一个主菜单
InBlock.gif
            MenuStrip mainMenu = new MenuStrip();
InBlock.gif            DataSet ds 
= new DataSet();
InBlock.gif            
//从XML中读取数据。数据结构后面详细讲一下。
InBlock.gif            
//StreamReader sr = new StreamReader(menuContent);
InBlock.gif            
//ds.ReadXml(sr);
InBlock.gif
            ds.ReadXml(Path.Combine(Application.StartupPath, "..\\..\\MenuItem\\MenuItem.xml"));
InBlock.gif            DataView dv 
= ds.Tables[0].DefaultView;
InBlock.gif            
//通过DataView来过滤数据首先得到最顶层的菜单
InBlock.gif
            dv.RowFilter = "ParentItemID=0";
InBlock.gif            
for (int i = 0; i < dv.Count; i++)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
//创建一个菜单项
InBlock.gif
                ToolStripMenuItem topMenu = new ToolStripMenuItem();
InBlock.gif                
//给菜单赋Text值。也就是在界面上看到的值。
InBlock.gif
                topMenu.Text = dv[i]["Text"].ToString();
InBlock.gif                topMenu.Name 
= dv[i]["ItemID"].ToString();
InBlock.gif                
//如果是有下级菜单则通过CreateSubMenu方法来创建下级菜单
InBlock.gif
                if (Convert.ToInt16(dv[i]["IsModule"]) == 1)
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    
//以ref的方式将顶层菜单传递参数,因为他可以在赋值后再回传。--也许还有更好的方法^_^.
InBlock.gif
                    CreateSubMenu(ref topMenu, Convert.ToInt32(dv[i]["ItemID"]), ds.Tables[0]);
ExpandedSubBlockEnd.gif                }

InBlock.gif                
//显示应用程序中已打开的 MDI 子窗体列表的菜单项
InBlock.gif
                mainMenu.MdiWindowListItem = topMenu;
InBlock.gif                
//将递归附加好的菜单加到菜单根项上。
InBlock.gif
                mainMenu.Items.Add(topMenu);
ExpandedSubBlockEnd.gif            }

InBlock.gif
InBlock.gif            ToolStripMenuItem exitMenu 
= new ToolStripMenuItem();
InBlock.gif            mainMenu.Dock 
= DockStyle.Top;
InBlock.gif            
//将窗体的MainMenuStrip梆定为mainMenu.
InBlock.gif
            this.menuStrip1 = mainMenu;
InBlock.gif            
//这句很重要。如果不写这句菜单将不会出现在主窗体中。
InBlock.gif
            this.Controls.Add(mainMenu);
ExpandedSubBlockEnd.gif        }

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//**/
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// 创建子菜单
InBlock.gif        
/// </summary>
InBlock.gif        
/// <param name="topMenu">父菜单项</param>
InBlock.gif        
/// <param name="ItemID">父菜单的ID</param>
ExpandedSubBlockEnd.gif        
/// <param name="dt">所有菜单数据集</param>

InBlock.gif        private void CreateSubMenu(ref ToolStripMenuItem topMenu, int ItemID, DataTable dt)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            DataView dv 
= new DataView(dt);
InBlock.gif            
//过滤出当前父菜单下在所有子菜单数据(仅为下一层的)
InBlock.gif
            dv.RowFilter = "ParentItemID=" + ItemID.ToString();
InBlock.gif
InBlock.gif            
for (int i = 0; i < dv.Count; i++)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
//创建子菜单项
InBlock.gif
                ToolStripMenuItem subMenu = new ToolStripMenuItem();
InBlock.gif                subMenu.Text 
= dv[i]["Text"].ToString();
InBlock.gif                subMenu.Name 
= dv[i]["ItemID"].ToString();
InBlock.gif                
//如果还有子菜单则继续递归加载。
InBlock.gif
                if (Convert.ToInt16(dv[i]["IsModule"]) == 1)
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    
//递归调用
InBlock.gif
                    CreateSubMenu(ref subMenu, Convert.ToInt32(dv[i]["ItemID"]), dt);
ExpandedSubBlockEnd.gif                }

InBlock.gif                
else
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    
//扩展属性可以加任何想要的值。这里用formName属性来加载窗体。
InBlock.gif
                    subMenu.Tag = dv[i]["FormName"].ToString();
InBlock.gif                    
//给没有子菜单的菜单项加事件。
InBlock.gif
                    subMenu.Click += new EventHandler(subMenu_Click);
ExpandedSubBlockEnd.gif                }

InBlock.gif                
//if (dv[i]["ImageName"].ToString().Length > 0)
InBlock.gif                
//{
InBlock.gif                
//    //设置菜单项前面的图票为16X16的图片文件。
InBlock.gif                
//    Image img = Image.FromFile(@"..\..\Image\" + dv[i]["ImageName"].ToString());
InBlock.gif                
//    subMenu.Image = img;
InBlock.gif                
//    subMenu.Image.Tag = dv[i]["ImageName"].ToString();
InBlock.gif                
//}
InBlock.gif                
//将菜单加到顶层菜单下。
InBlock.gif
                topMenu.DropDownItems.Add(subMenu);
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//**/
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// 菜单单击事件
InBlock.gif        
/// </summary>
InBlock.gif        
/// <param name="sender"></param>
ExpandedSubBlockEnd.gif        
/// <param name="e"></param>

InBlock.gif        void subMenu_Click(object sender, EventArgs e)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
//tag属性在这里有用到。
InBlock.gif
            string formName = ((ToolStripMenuItem)sender).Tag.ToString();
InBlock.gif            CreateFormInstance(formName, Convert.ToInt32(((ToolStripMenuItem)sender).Name));
ExpandedSubBlockEnd.gif        }

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//**/
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// 创建form实例。
InBlock.gif        
/// </summary>
ExpandedSubBlockEnd.gif        
/// <param name="formName">form的类名</param>

InBlock.gif        private void CreateFormInstance(string formName,int id)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
bool flag = false;
InBlock.gif            
//遍历主窗口上的所有子菜单
InBlock.gif
            for (int i = 0; i < this.MdiChildren.Length; i++)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
//如果所点的窗口被打开则重新激活
InBlock.gif
                if (this.MdiChildren[i].Tag.ToString().ToLower() == formName.ToLower())
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    
this.MdiChildren[i].Activate();
InBlock.gif                    
this.MdiChildren[i].Show();
InBlock.gif                    
this.MdiChildren[i].WindowState = FormWindowState.Normal;
InBlock.gif                    flag 
= true;
InBlock.gif                    
break;
ExpandedSubBlockEnd.gif                }

ExpandedSubBlockEnd.gif            }

InBlock.gif            
if (!flag)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
//如果不存在则用反射创建form窗体实例。
InBlock.gif
                Assembly asm = Assembly.Load("Kimbanx.SecurityDiskSystem.FactoryTools");//程序集名
InBlock.gif
                object frmObj=null;
InBlock.gif                
switch(id)
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    
case 48:
ExpandedSubBlockStart.gifContractedSubBlock.gif                         frmObj 
= Activator.CreateInstance(Type.GetType("Kimbanx.SecurityDiskSystem.FactoryTools." + formName), new object[] dot.gif{ ConfigFormState.Create, "创建策略配置" });
InBlock.gif                        
break;
InBlock.gif                    
case 49:
ExpandedSubBlockStart.gifContractedSubBlock.gif                         frmObj 
= Activator.CreateInstance(Type.GetType("Kimbanx.SecurityDiskSystem.FactoryTools." + formName), new object[] dot.gif{ ConfigFormState.View, "查看策略配置" });
InBlock.gif
InBlock.gif                        
break;
InBlock.gif                    
case 50:
ExpandedSubBlockStart.gifContractedSubBlock.gif                         frmObj 
= Activator.CreateInstance(Type.GetType("Kimbanx.SecurityDiskSystem.FactoryTools." + formName), new object[] dot.gif{ ConfigFormState.Import, "迁入策略配置" });
InBlock.gif
InBlock.gif                        
break;
InBlock.gif                    
case 51:
ExpandedSubBlockStart.gifContractedSubBlock.gif                         frmObj 
= Activator.CreateInstance(Type.GetType("Kimbanx.SecurityDiskSystem.FactoryTools." + formName), new object[] dot.gif{ ConfigFormState.Export, "迁出策略配置" });
InBlock.gif
InBlock.gif                        
break;
InBlock.gif                    
case 52:
ExpandedSubBlockStart.gifContractedSubBlock.gif                         frmObj 
= Activator.CreateInstance(Type.GetType("Kimbanx.SecurityDiskSystem.FactoryTools." + formName), new object[] dot.gif{ ConfigFormState.ExportManagementCenter, "导出管控中心用策略配置(企业版)" });
InBlock.gif
InBlock.gif                        
break;
InBlock.gif                    
default:
InBlock.gif                         frmObj 
= Activator.CreateInstance(Type.GetType("Kimbanx.SecurityDiskSystem.FactoryTools." + formName));
InBlock.gif                        
break;
ExpandedSubBlockEnd.gif                }

InBlock.gif                
InBlock.gif               
// object frmObj = asm.CreateInstance("Kimbanx.SecurityDiskSystem.FactoryTools." + formName);//程序集+form的类名。
InBlock.gif
                Form frms = (Form)frmObj;
InBlock.gif                
//tag属性要重新写一次,否则在第二次的时候取不到。原因还不清楚。有知道的望告知。
InBlock.gif
                frms.Tag = formName.ToString();
InBlock.gif                frms.MdiParent 
= this;
InBlock.gif                frms.Show();
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

InBlock.gif
ExpandedSubBlockEnd.gif    }

ExpandedBlockEnd.gif}

菜单的xml文件如下所示:这个是我从别人的博客中摘抄的。

<? xml version="1.0" encoding="utf-8"  ?>
None.gif
< Menus >
None.gif    
< MenuItem >
None.gif        
< Text > 资料管理 </ Text >
None.gif        
< ItemID > 1000 </ ItemID >
None.gif        
< ParentItemID > 0 </ ParentItemID >
None.gif        
< FormName ></ FormName >
None.gif        
< IsModule > 1 </ IsModule >
None.gif        
< Level > 1 </ Level >
None.gif        
< ImageName > 01.bmp </ ImageName >
None.gif    
</ MenuItem >
None.gif    
< MenuItem >
None.gif        
< Text > 产品管理 </ Text >
None.gif        
< ItemID > 1100 </ ItemID >
None.gif        
< ParentItemID > 0 </ ParentItemID >
None.gif        
< FormName ></ FormName >
None.gif        
< IsModule > 1 </ IsModule >
None.gif        
< Level > 1 </ Level >
None.gif        
< ImageName > 16x16_ico_pdf.gif </ ImageName >         
None.gif    
</ MenuItem >
None.gif    
< MenuItem >
None.gif        
< Text > 进书管理 </ Text >
None.gif        
< ItemID > 100001 </ ItemID >
None.gif        
< ParentItemID > 1000 </ ParentItemID >
None.gif        
< FormName > frmInputBooks </ FormName >
None.gif        
< IsModule > 0 </ IsModule >
None.gif        
< Level > 2 </ Level >
None.gif        
< ImageName > crest16x16.gif </ ImageName >
None.gif    
</ MenuItem >
None.gif    
< MenuItem >
None.gif        
< Text > 买卖管理 </ Text >
None.gif        
< ItemID > 100002 </ ItemID >
None.gif        
< ParentItemID > 1000 </ ParentItemID >
None.gif        
< FormName ></ FormName >
None.gif        
< IsModule > 1 </ IsModule >
None.gif        
< Level > 2 </ Level >
None.gif        
< ImageName > ico16-16.gif </ ImageName >
None.gif    
</ MenuItem >
None.gif    
< MenuItem >
None.gif        
< Text > 作业管理 </ Text >
None.gif        
< ItemID > 110001 </ ItemID >
None.gif        
< ParentItemID > 1100 </ ParentItemID >
None.gif        
< FormName ></ FormName >
None.gif        
< IsModule > 1 </ IsModule >
None.gif        
< Level > 2 </ Level >
None.gif        
< ImageName > ico_info_16x16_mask.gif </ ImageName >
None.gif    
</ MenuItem >
None.gif    
< MenuItem >
None.gif        
< Text > 买书管理 </ Text >
None.gif        
< ItemID > 10000201 </ ItemID >
None.gif        
< ParentItemID > 100002 </ ParentItemID >
None.gif        
< FormName ></ FormName >
None.gif        
< IsModule > 1 </ IsModule >
None.gif        
< Level > 3 </ Level >
None.gif        
< ImageName > ico_tmn_16x16.jpg </ ImageName >
None.gif    
</ MenuItem >
None.gif    
< MenuItem >
None.gif        
< Text > 买sss管理 </ Text >
None.gif        
< ItemID > 1000020101 </ ItemID >
None.gif        
< ParentItemID > 10000201 </ ParentItemID >
None.gif        
< FormName > frmBuyBook </ FormName >
None.gif        
< IsModule > 0 </ IsModule >
None.gif        
< Level > 4 </ Level >
None.gif        
< ImageName > ico16-16.gif </ ImageName >
None.gif    
</ MenuItem >
None.gif    
< MenuItem >
None.gif        
< Text > dsafasdf </ Text >
None.gif        
< ItemID > 11000101 </ ItemID >
None.gif        
< ParentItemID > 110001 </ ParentItemID >
None.gif        
< FormName > frmBuyBook </ FormName >
None.gif        
< IsModule > 0 </ IsModule >
None.gif        
< Level > 3 </ Level >
None.gif        
< ImageName > ico16-16.gif </ ImageName >
None.gif    
</ MenuItem >
None.gif
</ Menus >
下面来说明一下XML文件。
Text:为显示在窗体上的文字,
ItemID:为菜单的ID,
ParentItemID:为此菜单的父菜单ID如果是顶级菜单则为0
FormName:为单击菜单所要显示的窗体类名如果是还有下级菜单的则不要写。
IsModule:是否还有子菜单1有,0没有
Level:菜单所在的层数。目前还没用到。
ImageName:菜单前的图标为16x16的图片文件,这个我这里没有用到

在这里还可以根据自己的需要加其它的属性,也可以写成以数据库的方式。
这是我目前用到的功能。我会继续发表我做这个小软件的心得体会。希望对大家有所帮助。

转载于:https://www.cnblogs.com/virusswb/archive/2008/07/03/1234889.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值