gpt4 book ai didi

c# - 如何获取Windows窗体中的按钮控件 - Panel

转载 作者:太空狗 更新时间:2023-10-29 19:58:49 24 4
gpt4 key购买 nike

获取表单中的所有按钮,包括相同形式的面板中的按钮..

最佳答案

 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);
}
}

关于c# - 如何获取Windows窗体中的按钮控件 - Panel,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6421292/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com