Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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:

 

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?

Chaos is merely logic beyond human comprehension
Posted

to my knowledge you cannot specify at first that you want only labels, so you have to:

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

  • Leaders
Posted
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).
[sIGPIC]e[/sIGPIC]
Posted
Thanks very much guys, that was exactly what I was after - gonna go run to my app now and finish it off. Thanks again! ^^
Chaos is merely logic beyond human comprehension

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...