VB6 控件数组最简单的 .NET 等价物是什么? [英] What's the simplest .NET equivalent of a VB6 control array?

查看:20
本文介绍了VB6 控件数组最简单的 .NET 等价物是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

也许我只是对 .NET 还不够了解,但我还没有看到一种令人满意的方法来在 .NET 中轻松实现这个简单的 VB6 代码(假设此代码位于数组 Command1 中包含 N 个 CommandButtons 的表单上() 和数组 Text1()) 中的 N 个文本框:

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

我知道这不是很有用的代码,但它展示了在 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?

推荐答案

制作一个通用的文本框列表:

Make a generic list of textboxes:

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;
}

这篇关于VB6 控件数组最简单的 .NET 等价物是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆