List<Control> controls = new List<Control>();
        public Form2()
        {
            InitializeComponent();
            controls.Clear();
            foreach (Control ctrl in Form1.Controls)
            {
                controls.Add(ctrl);                
            }
            foreach (Control ctrl in controls)
            {
                ctrl.parent = this;
            }
        }

这段代码是我在codeproject 上面看到的,虽然不是很相同,但是大概的意思是这样的。就是用foreach 循环一个窗体中的所有控件,然后把这些控件放到list中,再从list 中用foreach 方法取出来。起初我的想法就是这哥们真傻。。。直接  

foreach (Control ctrl in Form1.Controls)

            {
                ctrl.parent  =this;
            }

 就可以搞定啊。。于是我就在项目中用到了这个,然后我很快的就发现了问题。直接这样做循环不完全。。原因不详。。

希望有识之士能给出个答案。我就不在深究下去了。。 

 

 

相关文章:

  • 2021-06-26
  • 2021-12-22
  • 2021-10-19
  • 2022-01-17
  • 2021-12-02
  • 2021-08-18
  • 2022-12-23
猜你喜欢
  • 2021-10-31
  • 2022-12-23
  • 2021-11-26
  • 2021-05-14
  • 2021-08-07
  • 2021-08-09
  • 2021-06-03
相关资源
相似解决方案