我有以下文本框,希望更快地删除它们。
TxtDrawA1.Clear
TxtDrawA2.Clear
TxtDrawA3.Clear
TxtDrawA4.Clear
TxtDrawA5.Clear
TxtDrawA6.Clear
TxtDrawA7.Clear
TxtDrawA8.Clear
and so on...
答案 0 :(得分:1)
在这里,无论它们位于哪个容器中(它们甚至都可以位于不同的容器中),如何找到它们。这种方法还演示了如何“按顺序”获得这些控件:
Dim tb As TextBox
Dim ctl As Control
For i As Integer = 1 To 8
ctl = Me.Controls.Find("TxtDrawA" & i, True).FirstOrDefault
If Not IsNothing(ctl) AndAlso TypeOf (ctl) Is TextBox Then
tb = DirectCast(ctl, TextBox)
' ... do stuff with "tb" ...
tb.Clear()
End If
Next
答案 1 :(得分:0)
Hello and welcome to StackOverflow!
You could try iterating through the textboxes like this:
For Each txtb As TextBox In Me.Controls.OfType(Of TextBox)()
If txtb.Name.StartsWith("TxtDrawA")
txtb.Clear
End If
Next
Hope this helps!