Reputation: 145
I have made a form in VB10 with 50 buttons. How can i manage their visibility with a for loop ??
For example i want to do something like that:
For i As Integer = 1 To 50
Button(i).Visible = False
Next
How can i map the current number of the i? I want to avoid write it 50 times.
Thank you in advance for your help.
Upvotes: 1
Views: 86
Reputation: 39122
Here's how to get the buttons no matter what container they are in, even multiple ones:
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
Upvotes: 1
Reputation: 9024
If there names are Button1, Button2, etc then this will work:
For i As Integer = 1 To 50
Me.Controls("Button" & i.ToString).Visible = False
Next
Upvotes: 0