如我的菜单有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里都写一次啊。
不知道是不是说明白了。。

解决方案 »

  1.   

    http://chs.gotdotnet.com/quickstart/aspplus/
    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
      

  2.   

    看不懂singlepine(小山)给的连接和我的问题的关系
    请问doitnow2000(大海)这种模式怎么写
      

  3.   

    Floating (平淡.简单) 有没有试过委托.我觉得应可以的
      

  4.   

    private System.Collections.Hashtable h; private void setClickEvent(System.Windows.Forms.MenuItem m)
    {
    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);
    }
    }
      

  5.   

    MenuClick中生成一form的实例
    Form1_Load中把menu和form的对应关系保存到一张hash表中,并调用setClickEvent递归设置所有menu的click事件
      

  6.   

    jinjazz,我觉得这样不太好,因为Menu很多的状况下生成那么多实例很耗资源的,如果有的Form在Instance的时候做了很多操作的话,装载Menu会很慢。
    我的方式是这样:在MenuItem中保存Form的ClassName,然后用InvokeMember去实现。
    不过,这样执行效率应该会大打折扣。
      

  7.   

    jinjazz,不好意思,看错了。。你的方法可行。
      

  8.   

    我有生成很多实例吗?我只是在hash表中保存了type
      

  9.   

    {jinjazz(近身剪(充电中...))} ----牛!