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

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

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

制作文本框的通用列表:
  1. var textBoxes = new List<TextBox>();
  2.  
  3. // Create 10 textBoxes in the collection
  4. for (int i = 0; i < 10; i++)
  5. {
  6. var textBox = new TextBox();
  7. textBox.Text = "TextBox " + i;
  8. textBoxes.Add(textBox);
  9. }
  10.  
  11. // Loop through and set new values on textBoxes in collection
  12. for (int i = 0; i < textBoxes.Count; i++)
  13. {
  14. textBoxes[i].Text = "New value " + i;
  15. // or like this
  16. var textBox = textBoxes[i];
  17. textBox.Text = "New val " + i;
  18. }

猜你在找的VB相关文章