Looping through a specific control

CryoEnix

Regular
Joined
Jan 11, 2003
Messages
93
Location
Wrexham, Wales
Is it possible in VB.NET to loop through a specific object within a form? Below is the pseudocode to what I want to achieve:

Code:
for con = each Label in formMain
con.backcolor=rgb(252,252,254)
next

Is this possible, and if so does anybody know the correct syntax?
 
to my knowledge you cannot specify at first that you want only labels, so you have to:
Visual Basic:
dim ctl as control
for each ctl in formMain.Controls
  if typeof control is label then
    'do your magic here
  end if 'label
next
note you can also do this to just a panel or groupbox
 
Note that unless you do a recursive search for controls, you will only find controls placed directly on the form (in other words, controls placed in panels and group boxes won't be found).
 
Back
Top