什么是最简单的.NET等效的VB6控件数组?

前端之家收集整理的这篇文章主要介绍了什么是最简单的.NET等效的VB6控件数组?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
也许我还不太熟悉.NET,但我还没有看到一种令人满意的方式在.NET中轻松实现这个简单的VB6代码(假设这个代码在一个带有N CommandButtons的表单Command1()和N中数组Text1()中的TextBoxes:
Private Sub Command1_Click(Index As Integer)

   Text1(Index).Text = Timer

End Sub

我知道它不是非常有用的代码,但它证明了控制数组在VB6中的易用性. C#或VB.NET中最简单的等价物是什么?

制作文本框的通用列表:
var textBoxes = new List<TextBox>();

// Create 10 textBoxes in the collection
for (int i = 0; i < 10; i++)
{
    var textBox = new TextBox();
    textBox.Text = "TextBox " + i;
    textBoxes.Add(textBox);
}

// Loop through and set new values on textBoxes in collection
for (int i = 0; i < textBoxes.Count; i++)
{
    textBoxes[i].Text = "New value " + i;
    // or like this
    var textBox = textBoxes[i];
    textBox.Text = "New val " + i;
}
原文链接:https://www.f2er.com/vb/255899.html

猜你在找的VB相关文章