foreach(Control item in this.controls)
{
  if(item.name=="ImageList1")
     userControl.image=(ImageList)item
}

解决方案 »

  1.   


    foreach(Control item in this.controls)
    {
      if(item.GetType==(new ImageList()).GetType())
         //...
    }
      

  2.   

    系统提示:
     Cannot convert type 'System.Windows.Forms.Control' to 'System.Windows.Forms.ImageList'呵呵!
      

  3.   

    private ImageList _image=new ImageList();
    public ImageList Image
    {
    set
    {
    _image=value;
    }
    get
    {
    return _image;
    }
    }
      

  4.   

    public ImageList ImageList
    {
    get
    {
    foreach(ImageList item in this.Parent.Controls)
    {
    if(item!=null)
    imageList=item;
    }
    imageList;
             }

    }
    我改写了,不过总觉得似乎有问题…………
      

  5.   

    当然,这个是在我的 class MyControl:Control内的一个属性。
      

  6.   

    try 判断一下不就可以了,其实不光有Component的问题,Com控件也有问题。
      

  7.   

    To sarmoo (Echo):ImageList并不是继承自Control,所以通过Controls来判断根本方向不对.你可以在你的控件中定义一个 MyImageList属性,来在Form中创建这个控件的时候,对这个属性赋值.public class MyControl
    {
       private ImageList _imageList;
       public MyImageList
       { 
          set { _imageList = value;} //你也可以在这里写其他的处理
          get { return _imageList;}
        }
    }使用的时候,
    MyControl c = new MyControl();
    c.MyImageList = this.imageList1; //this是指Form
      

  8.   

    OK!我试了一下,只要设置了这个属性,当Form中增加ImageList时,控件的这个属性的列表就会自动把这个新的ImageList增加进去。
    原来这么简单,我把它想的太复杂了。
    谢谢各位的回答!
    准备结贴!
      

  9.   

    啊!来晚了。做一个ImageList的属性是正确的方法。