我如何能得到按钮控件在Windows窗体 - 面板 [英] How Can I Get The Button Controls in Windows Form - Panel
本文介绍了我如何能得到按钮控件在Windows窗体 - 面板的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
让所有的按钮在表单中包括
以相同的形式面板的按钮。
解决方案
列表<控制>名单=新名单,LT;控制>();
GetAllControl(这一点,清单);
的foreach(在列表控制控制)
{
如果(control.GetType()== typeof运算(按钮))
{
//所有BTN
}
}
私人无效GetAllControl(控制C,列表与LT;控制>的列表)
{
的foreach(在c.Controls控制控制)
{
list.Add(对照组);
如果(control.GetType()== typeof运算(面板))
GetAllControl(控制清单);
}
}
Get All the Buttons In A Form including the buttons in the panel of the same form..
解决方案
List<Control> list = new List<Control>();
GetAllControl(this, list);
foreach (Control control in list)
{
if (control.GetType() == typeof(Button))
{
//all btn
}
}
private void GetAllControl(Control c , List<Control> list)
{
foreach (Control control in c.Controls)
{
list.Add(control);
if (control.GetType() == typeof(Panel))
GetAllControl(control , list);
}
}
这篇关于我如何能得到按钮控件在Windows窗体 - 面板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文