本帖最后由 liohoym 于 2009-12-17 10:27:24 编辑

解决方案 »

  1.   

    foreach(Control   control   in   this.Controls)   
      {
    //......   
    }
      

  2.   

    foreach(Control control in Controls)
    {
    只懂列出控件的,不懂sqlConnection;
    }
      

  3.   

    foreach(Control  control  in  this.Controls)  
      { 
    //......  
    }OK
      

  4.   

    面试题吧!?!?foreach (System.Windows.Forms.Control control in this.Controls)
    {
    if (control is System.Windows.Forms.TextBox)
    {
    System.Windows.Forms.TextBox tb = (System.Windows.Forms.TextBox)control ;
    tb.Text = String.Empty ;
    }
    }
      

  5.   

    我是遍历了所有Textbox并清空了他们的值!?!!?
      

  6.   

    foreach (Control ct in this.Controls)
    {}这样的时候,表单中的好多东西列不出来的.
      

  7.   

    就这样!另外图片不上传到QQ空间里再引导到这里。
    这样论坛不显示,可以将图片传到csdn论坛空间相册在引用。
      

  8.   


    这样可以将我在设计时就放在表单中的sqlConnection,SqlDataAdapter列出来吗?好像不能哟...
      

  9.   

        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();            DoIt(this.Controls );
            }        void DoIt(Control.ControlCollection CC)
            {
                foreach (Control C in CC)
                {
                    MessageBox.Show(C.Name);                DoIt(C.Controls);
                }
            }
        }
      

  10.   

    用Controls集合,好像只能列出继承自Control类的成员.
      

  11.   

    foreach(Control  control  in  this.Controls) 
      {}
      

  12.   

    就像我上面的图中,如果用Controls只能列出四个:
    comboBox1,button1,propertyGrid1,treeView1还有三个不能列出来:form1,sqlConection1,sqlCommandBuild1我是想这七个东西全部列出来.
      

  13.   

    sqlconnection 等不要用vs自带的,自己写
      

  14.   


    自已写不写没关系,关健我要把已经放在FORM上的给列出来.
      

  15.   

    foreach (System.Windows.Forms.Control control in this.Controls)
    {
    if (control is System.Windows.Forms.TextBox)
    {
    System.Windows.Forms.TextBox tb = (System.Windows.Forms.TextBox)control ;
    tb.Text = String.Empty ;
    }
    }
      

  16.   

    遍历组件就不一样了foreach (Component C in this.components.Components)
                {
                    MessageBox.Show(C.ToString());                if (C is Timer)
                    {
                        Timer T = (Timer)C;
                    }
                }
      

  17.   

    如果是取名字,这个可以取所有control和componentusing System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Text;
    using System.Windows.Forms;
    using System.Reflection;namespace WindowsApplication230
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();            foreach (FieldInfo FI in this.GetType().GetFields(BindingFlags.Instance | BindingFlags.NonPublic))
                    if (FI.FieldType.IsSubclassOf(typeof(Component)))
                        MessageBox.Show(FI.Name);
            }
        }
    }
      

  18.   

    foreach (Component C in this.components.Components) 
                { 
                    MessageBox.Show(C.ToString());                 if (C is Timer) 
                    { 
                        Timer T = (Timer)C; 
                    } 
                } 这个应该是对的。
    再不行你就反射了。
      

  19.   

    我放了一个timer,运行结果是弹出字符串
    [System.Windows.Forms.TImer], Interval: 100还有,你是用03吗
      

  20.   

    if (this.components != null)
                {
                    foreach (Component c in this.components.Components)
                    {
                        MessageBox.Show(c.ToString());
                    }
                }