首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

winform中怎么获得窗体中所有的控件

2012-01-30 
winform中如何获得窗体中所有的控件我想用遍例查出窗体内所有的botton控件。如何写?[解决办法]C# codeforea

winform中如何获得窗体中所有的控件
我想用遍例查出窗体内所有的botton控件。如何写?


[解决办法]

C# code
foreach(Control ctl in Controls)     {     if(ctl is Button) //or if(ctl.GetType()==(new Button()).GetType)     ..     //其它类似        }
[解决办法]
考虑容器控件. 若button在容器里.

C# code
private void seachbutton(Control.ControlCollection controls)        {            foreach (Control c in controls)            {                if (c is Button)                    { .....}                else                    if (c.Controls.Count > 0)                        seachbutton(c.Controls);            }        } 

热点排行