"Hansen" <he******@hotmail.com> wrote in
news:11*********************@p10g2000cwp.googlegro ups.com:
I have a form with multiple labels and textboxes and listboxes
that need to be made visible and not visible when buttons are
clicked. Is there anyway of grouping them together so that I have
less lines of code instead of 100's of lines stating:
LblA.Visible = True
LblB.Visible = True
LblC.Visible = True
LblD.Visible = True
LblE.Visible = True
LblF.Visible = True ..etc., etc. and then making them not visible
again at a later stage and thus repeating the same lines of code?
By default Visible = False for most of the objects on the form.
When I need to do this kind of thing, I use a custom collection (or
several of them) make this more efficient. I use the controls' .Tag
property to group them, and walk the Controls collection to set up
the collections.
1. assign appropriate .Tag properties, a unique value for each group
of controls (e.g., "label" for all your labels, "combo" for combo
boxes, "checkbox" for Checkboxes; these are examples since all of
these are things you could find out from checking the ControlType).
2. in the OnLoad event of your form, loop through the Controls
collection and populate your collections, using either the .Tag
property or the .ControlType to determine which collection to assign
them to.
3. once you've done that, then you can loop through each collection
of controls and change properties any way you like.
I've posted more detailed instructions on how to accomplish this in
the past. If you search Google Groups in this newsgroup for my name
and "custom collection" you are likely to be able to find pretty
explicit instructions for how to accomplish the above tasks.
I only use custom collections, though, when I want to switch things
on and off multiple times in a form session. If I just wanted to set
up the form when opening it, I'd just walk the controls collection
and do it once.
--
David W. Fenton
http://www.dfenton.com/
usenet at dfenton dot com
http://www.dfenton.com/DFA/