使用反射!
Type t = Type.GetType("someClassName");
t = Assembly.GetAssembly(t).GetType("someClassName");
object o = Activator.CreateInstance(t);//这样就得到了实例

解决方案 »

  1.   

    kenMoxi(蓝雨)这种方法是可以,但我有很多这样的东西
    而且像Form aa = new Form();我都是存在数据库里,如果能把这个字符串当成
    语句执行是最好的呢,希望你能帮我,谢谢
    就像数据库里有 exec 'selct * from Table' 一样
      

  2.   

    string str="Form aa = new Form()";
    调用方法exec(str);是弹出这个窗体,而不是这个字符串
      

  3.   

    有容易的方法解决吗,help,help~~~~~~~~~~~~~~~~~
      

  4.   

    string str="Form aa = new Form()"  
    "Form"类里的方法,属性都用什么样的方式存在?
      

  5.   

    你把Form aa = new Form();写到Button事件里 你点多少次按钮就能New多少个窗体
      

  6.   

    是呀,但是我现在是作为一个字符串
    我要怎么处理这个字符串就相当于new 多少个窗体
      

  7.   

    高难度!
    string str="Form aa = new Form()"  
    ......
    回家想想!还有5分钟就要下班了!
      

  8.   

    有一篇介绍用 C# 实现类似 JavaScript 中 eval 函数功能的文章
    用的就是动态编译的技术
    楼主可去查查看.
      

  9.   

    http://www.c-sharpcenter.com/CSNET/dynamicinvoke.asp
    http://www.c-sharpcorner.com/Code/2002/April/LoadingAssemblyInfo.asp
    使用反射生成一个窗体:
    private void button1_Click(object sender, System.EventArgs e)
    {
    Assembly assm = Assembly.LoadFrom("e:\\WindowsApplication5.dll");
    Type TypeToLoad= assm.GetType("WindowsApplication5.Form1");

    object obj;
    obj = Activator.CreateInstance(TypeToLoad);
    Form formToShow = null;
    formToShow = (Form)obj;
    formToShow.Show();

    }
      

  10.   

    private void miTemp_Click(object sender, EventArgs e) {
    try {
    mItemClass mi = sender as mItemClass;
    string []strTemp = mi.Form.ToString().Split(';');
    Assembly ass =Assembly.LoadFrom(Application.StartupPath+"\\RNP.UI.dll");
    Type tp = ass.GetType(strTemp[0],false,true); 
    // Type tp = ass.GetType("RNP.UI.BaseData.RetailConsignAdd",false,true);  BindingFlags bflags = BindingFlags.DeclaredOnly | BindingFlags.Public 
    | BindingFlags.NonPublic | BindingFlags.Instance;
    //调用构造函数并获得对象
    object[] arg=new object[]{this,this.mUserInfo};
    object obj = tp.InvokeMember(strTemp[1], bflags | 
    BindingFlags.CreateInstance, null, null, arg);// (obj as RNP.UI.IForm).CreateFrm(this,this.mUserInfo);
    }
    catch(Exception ex) {
    MessageBox.Show("打开窗体失败!!!"+ex.Message,"错误信息",MessageBoxButtons.OK,MessageBoxIcon.Error);
    }
    }
      

  11.   

    本人用这种方法可以完成我要的功能,但是有些窗体有问题,有些
    窗体又没有这种问题:在RNP.UI里找不到资源文件