遍历窗体中所有控件的信息

public void TraverControl(Control Ctl)
 {
   foreach (Control c in Ctl.Controls)
  {
     label1.Text += " " + "" + c.Name + "" + " ";
     //用于显示窗体中包含的所有的控件名,首先显示的是最外层的控件
     if (c.Controls.Count == 0)
    {
      continue;
    }

    else
     {
       Control C = c;
       TraverControl(C); //递归调用
     }

  }

 }

private void button1_Click(object sender, EventArgs e)

 {
   TraverControl(this);//调用递归函数
 
 }

You can reach me by surfing the web ---- huntjobs.cn,or sending e-mails to me,Here is my qq MailBox:1424870395@qq.com
原文地址:https://www.cnblogs.com/HedgehogBlog/p/3673698.html