int i=0;
foreach (Control c in this.Controls)
{
i++;
}
MessageBox.Show(i.ToString());

解决方案 »

  1.   

    For Each ctrl In Me.Controls
       If ctrl.GetType.ToString() = "System.Windows.Forms.TextBox" Then
          Console.Write(DirectCast(ctrl, TextBox).Name)
       End If
    NextMsgbox Me.Controls.Count
      

  2.   

    int i=0;
    foreach (Control c in this.Controls)
    {
    Control t=c as Button;
    if(t!=null)t.Name=" b"+i.ToString();
    i++;
    }
    MessageBox.Show(i.ToString()+this.Controls[0].Name);
      

  3.   

    你可以通过this.Controls.Count来统计窗口中控件的总数(服务器控件)