我有20多个文本框,全部命名为: TxtCustom1 TxtCustom2 TxtCustom3 等等...
我希望能够通过一个int连接动态构建文本框var name来循环分配这些文本框值,这样我的循环就像这个伪代码:
For Each pair In Dictionary
TxtCustom{pair.key}.Text = pair.Value
Next
在vb.net中是否可以像这样动态构建名称,如何实现这样的目标?
答案 0 :(得分:2)
似乎最好使用某种类型的控件(如网格),而不是一系列名称跟随模板的文本框,但这里是基于您讨论的场景的方式。
For Each pair In Dictionary
Me.Controls(String.format("TxtCustom{0}",pair.key)).Text= pair.Value
Next