What#39;s the simplest .NET equivalent of a VB6 control array?(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 等价物是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:VB6 控件数组最简单的 .NET 等价物是什么?
基础教程推荐
- WPF 模态进度窗口 2022-01-01
- C# 从 List<List<int>> 中删除重 2022-01-01
- 如果有人提交恶意软件Nuget包怎么办? 2022-01-01
- 如何使用 .Net 检查 Active Directory 服务器是否已启动并正在运行? 2022-01-01
- 当值可以是对象或空数组时反序列化 JSON 2022-01-01
- 禁止输入少量字符,例如'<'、'&a 2022-01-01
- .NET SerialPort DataReceived 事件未触发 2022-01-01
- Moq It.Is<>不匹配 2022-01-01
- Azure Functions:CosmosDBTrigger 未在 Visual Studio 中触发 2022-01-01
- 我应该在后面的代码中直接使用 Linq To SQL 还是使 2022-01-01
