什么是最简单的.NET相当于VB6的控件数组? [英] What's the simplest .NET equivalent of a VB6 control array?
本文介绍了什么是最简单的.NET相当于VB6的控件数组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
也许我只是不知道.NET不够好,但我还没有看到实现这个简单的VB6 code容易在.NET中(假设这code是一个窗体上的满意的方式ñCommandButton控件数组COMMAND1()和N文本框数组文本1()):
Maybe I just don't know .NET well enough yet, but I have yet to see a satisfactory way to implement this simple VB6 code easily in .NET (assume this code is on a form with N CommandButtons in array Command1() and N TextBoxes in array Text1()):
Private Sub Command1_Click(Index As Integer)
Text1(Index).Text = Timer
End Sub
我知道这是不是很有用code,但它体现了易用性,使控制阵列可以在VB6中使用。什么是最简单的等同于C#或VB.NET?
I know it's not very useful code, but it demonstrates the ease with which control arrays can be used in VB6. What is the simplest equivalent in C# or VB.NET?
推荐答案
请文本框的泛型列表:
List<TextBox> textBoxes = new List<TextBox>();
// Create 10 textboxes in the collection
for (int i = 0; i < 10; i++)
{
TextBox textBox = new TextBox();
textBox.Text = "Textbox " + i;
textBoxes.Add(textBox);
}
// Loop through and set new values on textboxes i collection
for (int i = 0; i < textBoxes.Count; i++)
{
textBoxes[i].Text = "New value " + i;
// or like this
TextBox textBox = textBoxes[i];
textBox.Text = "New val " + i;
}
这篇关于什么是最简单的.NET相当于VB6的控件数组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文