一般控件的遍历是foreach(Control con in this.controls) Statement
因为我写的是一个静态函数需要遍历,所以就没有this。用该对象名:frmPutInPexieElements
foreach(Control con in frmPutInPexieElements.      此时就没有controls这个变量了,只有controlcollection。但是controlcollection无法遍历。求指导

解决方案 »

  1.   

    我可能有些地方有问题。我把可能有问题的地方写出来
    以下是program里面的:
                Form frmPutInInsideOrientalElements = new frmPutInInsideOrientalElements();
                Form frmPutInObjCoordinates=new frmPutInObjCoordinates ();
                Form frmPutInOutSideOrientalElements=new frmPutInOutSideOrientalElements ();
                //Form frmPutInPixelsCoordinates = new frmPutInPixelsCoordinates();
                Application.Run(new frmPutInPixelsCoordinates());
    以下是另外一个类里面的(BeforeCount)
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Windows .Forms;
    namespace 摄影测量后方交会
    {
        class BeforeCount
        {
            private static  bool [] aCount=new bool[4];
            private static Form frmPutInInsideOrientalElements = new frmPutInInsideOrientalElements();
            static public void MakeAChange()
            {
                for (int i = 0; i < 4; i++)
                {
                    if (aCount[i] == true)
                    {                }
                }
            }
            static public void MakeAChange(int i)
            {
                switch (i)
                {
                    case 0: foreach (Control con in**就这里出问题了***)
                }
            }
        }
    }
      

  2.   

    静态的时候不存在this.
    都静态了你this指向啥?
      

  3.   

    你是不是想说 frmPutInPexieElements 然后输入点. 没有controls????如果是继承自control的控件都要有这个集合的,你看看是不是那点错了,这和静态不静态没关系 
      

  4.   

    对,我直接输入.Controls之后错误为需要引用对象。
    但是把frmPutInInsideOrientalElements输入后(我在BeforeCount里面定义过,并且分配了空间)就有.Controls
      

  5.   

    问题在于我在program里面定义过。并且分配了空间
    无论是frmPutInObjCoordinates还是frmPutInOutSideOrientalElements都不行