?
Solved

Make all controls visible

Posted on 2007-10-09
3
Medium Priority
?
180 Views
Last Modified: 2010-04-30
I'm working on a program in which I have maxed out the limit on controls I can use in one form.
Alot of the controls are not visible, I need to make all controls on the form visible in order to run some lines of code, then bring the form back to how it was before making them all visible again.
I'm sure thier is a better way to write the code for this than listing all of the controls (i.e. Text1.Visible = True) for every control.
Anyone know of a one line solution? I guess some sort of loop may work...but maybe theirs some code like  me.controls.visible = True (wait let me try that...) Nope, didn't work.
0
Comment
Question by:PME_Inc
  • 2
3 Comments
 
LVL 48

Assisted Solution

by:Wayne Taylor (webtubbs)
Wayne Taylor (webtubbs) earned 400 total points
ID: 20046249
Hi PME_Inc,

You can do something like this...

    Dim ctrl As Control
    For Each ctrl In Me.Controls
        ctrl.Visible = True
    Next

Regards,

Wayne
0
 
LVL 23

Accepted Solution

by:
ahammar earned 1600 total points
ID: 20046289
Hi again...
If you have some controls that you want visible at times, and not at other times, than the best way I've found is to put something in the controls tag property to identify when to hide and unhide it.  But if you have that many controls, then that is going to be a pain.  So, to start with:

This will hide or unhide every control:

    On Error Resume Next
    Dim c As Control
   
    For Each c In Me.Controls
            c.Visible = True 'or false to hide them all
    Next

But, when you hide them again, if you want to only hide the ones that were already hidden, then you are going to have to incorporate some kind if identifier into your code to mark each control that is currently hidden before they get showed.
So, since it sounds like you have far to many controls to go through and manually set the tag property of every control that you want hidden, then you are going to have to do something like this:

 When you show all controls, check each one first to see if it is hidden...if it is, then set it's tag property to whatever you want it to be...I'll use "Hide"
   
On Error Resume Next
    Dim c As Control
   
    For Each c In Me.Controls
            If c.Visible = False then
                  c.Tag = "Hide"
            Else
                  c.Tag = ""
            End if
            c.Visible = True
    Next


Now to hide them again:
    On Error Resume Next
    Dim c As Control
   
    For Each c In Me.Controls
            If cTag = "Hide" then c.Visible = False
    Next


You can also check the controls to see if they are hidden when the form loads and set their tags in the forms load event instead if you prefer

On Error Resume Next
    Dim c As Control
   
    For Each c In Me.Controls
            If c.Visible = False then
                  c.Tag = "Hide"
            Else
                  c.Tag = ""
            End if
    Next

So basically, if a controls tag says "Hide", then it will get hidden, otherwise it won't.
If you have controls that you have to hide at different times than other controls, than you will have to also incorporate the value of the tag into your app...
Something like in 1 event:
If c.Tag = "Group1" then
    Hide the control
End if

   and in another event:
If c.Tag = "Group2" then
    Hide the control
End if


Boy...I hope I made sense here...lol
If you need me to clarify any of this...let me know


:-)
ah
0
 
LVL 23

Expert Comment

by:ahammar
ID: 20047699
Thanks for the points and the grade!  Be sure to continue to ask about any problems you may have...

:-)
ah
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Computer science students often experience many of the same frustrations when going through their engineering courses. This article presents seven tips I found useful when completing a bachelors and masters degree in computing which I believe may he…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…
Suggested Courses
Course of the Month15 days, 8 hours left to enroll

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question