我在VB10中制作了一个带有50个按钮的表单。如何通过for循环管理其可见性? 例如,我想做类似的事情:
For i As Integer = 1 To 50
Button(i).Visible = False
Next
如何映射i的当前数量?我想避免写50次。
提前感谢您的帮助。
答案 0 :(得分:1)
这里是如何获取按钮,无论它们在哪个容器中,甚至是多个容器:
Dim matches() As Control
For i As Integer = 1 To 50
matches = Me.Controls.Find("Button" & i, True)
If matches.Length > 0 AndAlso TypeOf matches(0) Is Button Then
Dim btn As Button = DirectCast(matches(0), Button)
btn.Visible = False
End If
Next
答案 1 :(得分:0)
如果名称是Button1,Button2等,那么这将起作用:
For i As Integer = 1 To 50
Me.Controls("Button" & i.ToString).Visible = False
Next