我想测试一下反射的用法,就如下写法
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Reflection;namespace WindowsFormsApplication1
{
    public partial class Form2 : Form
    {
        public Form2()
        {
            InitializeComponent();
        }
       
        private void button1_Click(object sender, EventArgs e)
        {
            Assembly a = Assembly.LoadFrom("Form1.cs");
            
        }
    }
}
也就是想利用反射,打开一个窗体,后面就不知道如何写了,反正写了a.show()是没有用的,高人们帮忙指点一下吧,谢谢。

解决方案 »

  1.   

    string path=AssemblyName;
    string name=strName;  Form fm=(Form)Assembly.Load(path).CreateInstance(name);
    fm.MdiParent=this.ParentForm;
    fm.Show();
    fm.Dock=DockStyle.Fill;
      

  2.   

     string path = AssemblyName;
    这一句报错,提示Assemblyname 是类型,但是当变量来使用。
      

  3.   

     Form fm = (Form)Assembly.Load("WindowsFormsApplication1").CreateInstance("Form1");
                fm.Show();
    我改成如上可以通过编译,WindowsFormsApplication1 是命名空间,只是运行这个程序的时候,提示没有对像。奇怪。