foreach 이용한 같은타입 컨트롤 핸들링 - C#
프로그램/c# windows form 2009. 2. 25. 17:38 |foreach(Control ctl in this.Controls)
{
    if(ctl.GetType()== typeof(Label))
    {
        MessageBox.Show(ctl.Name);
    }
}
폼 위의 컨트롤 중 타입이 라벨인 것만 찾습니다...
혹은 인터페이스를 사용 하셔도 됩니다..
IEnumerator myEnurator = this.Controls.GetEnumerator();
while(myEnurator.MoveNext())
{
    if(myEnurator.Current.GetType() == typeof(Label))
    {
        MessageBox.Show(((Label)myEnurator.Current).Name);
    }
}








