private void (object obj)
{
   switch(obj.GetType().Name)
   case "WinFrom1";
         .....
         break;
   case "WinForm2":
         ......
         break;
}

解决方案 »

  1.   

    比如说
    Form1 f = new Form1();调用函数如下:
    xxx.xx(f);
    就ok了
    然后xx里面
    根据f.GetType().Name进行switch
      

  2.   

    再问一下,有没有办法不用switch挨个判断?
      

  3.   

    如果不用switch判断
    就要用反射
    关键是你要进行什么操作
    如果你能保证,任何窗体里面都有一个名字相同的方法
    而你要处理的就是调用这个方法
    那么通过反射来作你能确定吗?
      

  4.   

    事实上是这样,我有很多form,在某个事件中我希望打开某个页面,但是不要重复打开,这样我在打开前就要调用方法判断该页面是否已打开,如果没打开就打开,源代码如下(针对单个窗体)
    customer.customer_manager cust=null;
    foreach(Form f in this.MdiChildren) 


    if(f is customer.customer_manager) 


    cust= (customer.customer_manager)f; 
    break; 

    }   
    if( cust!= null)   
    {   
    cust.ShowDialog(); 
    cust.Focus();   
    }   
    else   
    {   
    cust=new customer.customer_manager();
    // cust.MdiParent=this;
    cust.ShowDialog();  
    cust.Focus(); 
    }
    这样的,我就需要在每一个打开窗体的事件中都需要重写这段代码,只是改一个窗体名字,我窗体很多,挨个使用switch也挺麻烦
      

  5.   

    public void ShowForms(Type t)
    {
      object obj = null;
        foreach(Form f in this.MdiChildren) 


    if(f is t) 


    obj = f; break; 

    }   
                  if(obj ==null)
                  {
                       obj = System.Activator.CreateInstance(t);               }
                       MethodInfo mif = t.GetMethod("Focus");
    mif.Invoke(obj,null);
    }
      

  6.   

    修改一下上面的代码
    public void ShowForms(Type t)
    --->
    public void ShowForms(string yourFormClassName)//传递你的窗体的类的名称,加上命名空间!
    {
        Type t = Type.GetType(yourFormClassName);
        .....下面的不变
    }