vb.net 循环顺序获取文本框名排序并赋值的多种方法
时间: 2024-02-28 09:57:33 浏览: 145
cop.rar_Cop vb_vb文本框赋值
以下是几种在 VB.NET 中循环顺序获取文本框名排序并赋值的方法:
1. 使用 For Each 循环遍历 Controls 集合,找到类型为 TextBox 的控件,并按名称排序:
```
Dim textBoxes = Me.Controls.OfType(Of TextBox)().OrderBy(Function(tb) tb.Name)
For Each tb In textBoxes
tb.Text = "Value"
Next
```
2. 使用 For 循环遍历 Controls 集合,找到类型为 TextBox 的控件,并按名称排序:
```
Dim textBoxes As New List(Of TextBox)
For Each c As Control In Me.Controls
If TypeOf c Is TextBox Then
textBoxes.Add(c)
End If
Next
textBoxes = textBoxes.OrderBy(Function(tb) tb.Name).ToList()
For i As Integer = 0 To textBoxes.Count - 1
textBoxes(i).Text = "Value"
Next
```
3. 使用 LINQ 查询语句从 Controls 集合中筛选出类型为 TextBox 的控件,并按名称排序:
```
Dim textBoxes = From c In Me.Controls
Where TypeOf c Is TextBox
Order By c.Name
Select CType(c, TextBox)
For Each tb In textBoxes
tb.Text = "Value"
Next
```
阅读全文