Reputation: 123
for i = 0 to 10
dim paneln as new panel
paneln.backcolor = color.red
if i = 5 then
paneln.backcolor = color.white
end if
me.controls.add(paneln)
next
Now I want to get the color of every panel on my form
red
red
red
red
white
red
red
red
red
red
Something like:
For Each p As Panel In Me.Controls
MsgBox(p.BackColor)
Next
Upvotes: 0
Views: 1030
Reputation: 3167
If you're using .Net 3.5 or 4.0, you can try:
For Each p as Panel In Me.Controls.OfType(Of Panel)
MessageBox.Show(p.BackColor)
Next
That will iterate through only the panel controls (or controls that derive from Panel), and ignore the others. Note that this only gets the panels that are directly on the form, and not any panels that are inside container objects, like other panels.
Upvotes: 1
Reputation: 81655
Try:
For Each p As Panel In Me.Controls.OfType(Of Panel)()
MessageBox.Show(p.BackColor.ToString())
Next
Upvotes: 0