再有一个问题,如果UserControl11这个类型事先没有在IDE中引用其DLL,而是在运行时动态的加载一个DLL并把该DLL中的控件显示出来,应该怎么做??谢谢大家,祝新年快乐.

解决方案 »

  1.   

    1.
    foreach(Object CtrObj in this.Controls)
    {
      if (CtrObj==你要删除的控件的引用) this.Controls.Remove();
      //或者你可以if (CtrObj.Name.ToString()=="名字") this.Controls.Remove();这样用
    }
      

  2.   

    2.
    filepath = "文件.dll";
    if (this._assembly==null)
    {
    this._assembly = Assembly.LoadFile(filepath);
    }
    类名 cls = this._assembly.CreateInstance(类名);
    //类名如果只知道string,可以声明一个Object cls来指向生成的类
      

  3.   

    1、this.SuspendLayout();//这个方法和稍后的ResumeLayout方法有什么作用???
    临时挂起控件的布局逻辑,直到调用 ResumeLayout 方法为止。这样会提高程序的性能。2、userControl11.Name = "userControl11";//这个name有什么意义?一般会在哪用到???
    可以用于识别该控件,比如解决你的第3个问题。3、怎么移除这个控件(确保不会发生资源泄露)??
    UserControl uc = null;
    foreach (Control ctrl in this.Controls)
    {
        if (ctrl.Name == "userControl11")
        {
            uc = (UserControl)ctrl;
            break;
        }
    }
    uc.Dispose();4、如果UserControl11这个类型事先没有在IDE中引用其DLL,而是在运行时动态的加载一个DLL并把该DLL中的控件显示出来,应该怎么做??
    为什么不先在IDE中引用该DLL?