也许我只是不知道.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;
}