gpt4 book ai didi

c# - 使用 foreach 循环检索 GroupBox 中的 TextBox

转载 作者:行者123 更新时间:2023-11-30 13:10:00 26 4
gpt4 key购买 nike

我在 WinForm 中有十个组框。每个组框包含10个文本框,我定义了每个TextBox名称。如何使用 foreach 循环获取每个文本框?

最佳答案

 foreach(Control gb in this.Controls)
{
if(gb is GroupBox)
{
foreach(Control tb in gb.Controls)
{
if(tb is TextBox)
{
//here is where you access all the textboxs.
}
}
}
}

但是如果您已经定义了每个文本框名称获得每个 TextBox 有什么意义?通过一个循环?

你可以定义一个 List<TextBox>持有每个 TextBox 的引用在创建它们时,只需浏览 List获得每个 TextBox 的访问权限.

关于c# - 使用 foreach 循环检索 GroupBox 中的 TextBox,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8224261/

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