有一个winform ,是个mdicontainer,上有很多个button,请问怎样得到这些button的集合?
------------------------------------------------------------------------------
要考虑其他的容器控件,比如说Panel最简单的情况如下
foreach(Button b in this.Controls)
{}但是如果有Panel还要对Panel做一个循环所以最好做一个递归的方法
如下:
private void FindButton(Control c)
{
if(c is Button)
{
MessageBox.Show("Button!");
}
if (c.Controls != null)
{
foreach(Control x in c.Controls)
{
FindButton(x);
}
}
}在窗体里面调用
this.FindButton(this);