c# 遍历控件

来源:互联网 发布:加工中心编程100例 编辑:程序博客网 时间:2024/05/17 02:09


public void GetControls(Control.ControlCollection ctc)

 {
            foreach (Control con in ctc)
            {
                if (!con.HasChildren)
                {
                    if (con.GetType().ToString() == "System.Windows.Forms.ComboBox")
                    {
                        (con as ComboBox).Text = "123";
                        continue;
                    }
                }
                GetControls(con.Controls);
            }
        }


/*-------调用---------*/

调用:  GetControls(this.Controls);

0 0
原创粉丝点击