如我的菜单有20项,如:MenuA,MenuB,MenuC...
同时对应的打开的页面有:FormA,FormB,FormC...MenuA Click是 FormA fa = new FormA(); fa.Show()
MenuB Click是 FormB fa = new FormB(); fa.Show()能不能写一个抽象的方法让这些事件只写一次,而不是每一个Menu Click里都写一次啊。
不知道是不是说明白了。。
同时对应的打开的页面有:FormA,FormB,FormC...MenuA Click是 FormA fa = new FormA(); fa.Show()
MenuB Click是 FormB fa = new FormB(); fa.Show()能不能写一个抽象的方法让这些事件只写一次,而不是每一个Menu Click里都写一次啊。
不知道是不是说明白了。。
http://www.xia8.com/SoftList/Catalog_151_SoftTime_Desc_1.html
http://coder.ylqh.com/share/
http://download.chinaitlab.com/
http://www.7880.com/Download/vbnet-5443.html
http://www.yesky.com/20020812/1624624.shtml
请问doitnow2000(大海)这种模式怎么写
{
m.Click+=new System.EventHandler(this.MenuClick);
foreach(System.Windows.Forms.MenuItem sub in m.MenuItems)
{
setClickEvent(sub);
}
}
private void MenuClick(object sender, System.EventArgs e)
{
Type t=(System.Type)h[(System.Windows.Forms.MenuItem)sender];
if (t!=null)
{
System.Windows.Forms.Form fa = (System.Windows.Forms.Form)Activator.CreateInstance(t);
fa.Show();
}
} private void Form1_Load(object sender, System.EventArgs e)
{
h=new System.Collections.Hashtable();
h.Add(menuItem2,typeof(Form2));
h.Add(menuItem3,typeof(Form3)); foreach(System.Windows.Forms.MenuItem m in this.mainMenu1.MenuItems)
{
setClickEvent(m);
}
}
Form1_Load中把menu和form的对应关系保存到一张hash表中,并调用setClickEvent递归设置所有menu的click事件
我的方式是这样:在MenuItem中保存Form的ClassName,然后用InvokeMember去实现。
不过,这样执行效率应该会大打折扣。