zoukankan      html  css  js  c++  java
  • c# 语言 winform 项目中 control.parent 的使用 (原创)

      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;
                }

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

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

  • 相关阅读:
    致21岁的自己
    nginx 入门实战
    软件测试的分类
    Springboot 使用 Jedis
    NodeJS模块、包、NPM
    NodeJS介绍
    毫秒必争,前端网页性能最佳实践--转载
    IT主要在线学习网站
    电商峰值系统架构设计--转载
    查看w3wp进程占用的内存及.NET内存泄露,死锁分析--转载
  • 原文地址:https://www.cnblogs.com/da6wei6/p/2173551.html
Copyright © 2011-2022 走看看