i want to add all declared buttons into my form
something like:
dim btn1,btn2,btn3 as new button
for each btn as button in declared.buttons
me.controls.add(btn)
next
You can add the buttons like this:
For i As Integer = 1 To 150
Dim btn As New Button()
btn.Name = "btn" + i.ToString()
Controls.Add(btn)
Next
Later, you can access the buttons like this:
Dim btn As Button = CType(Controls("btn1"), Button)
However, if you are needing to load that many controls dynamically, you may want to reconsider your design. It smells like a bad idea for most situations.
You can get all your buttons you've declared using something like this:
Dim buttons = From fi In Me.GetType().GetFields(BindingFlags.Instance Or BindingFlags.NonPublic)
Where fi.FieldType Is GetType(Button)
Select CType(fi.GetValue(Me), Button)
Off the top of my head.. Still working on it.. but You get the idea?
List(Of Button)first? Then you can loop them and do whatever you want to do with them.