C# 遍历控件名称

  List<string> list = new List<string>();
            list.Add("textBox2"); list.Add("textBox1"); list.Add("txtNum");

            StringBuilder sb = new StringBuilder();
 
            foreach (Control ctl in this.Controls)
            {
                if (ctl is TextBox)
                {
                    //txtNum
                    var obj = ctl.Name;
                    sb.AppendFormat("list.Add(\"{0}\");",obj);
                }
            }
           var name =  sb.ToString();

 

posted @ 2019-11-01 09:50  enych  阅读(713)  评论(0编辑  收藏  举报