Click here to Skip to main content
15,896,493 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi All

How to Male Form Load All Checkbox Visible False

VB
For Each Control In Me.Controls
            If TypeOf Control Is CheckBox Then
                Control.visible = False
            End If
        Next Control

Please Tell me..
Posted
Updated 5-Mar-13 6:12am
v2
Comments
[no name] 5-Mar-13 12:15pm    
Maybe you add some details to your question, like why you think that this code does not work?

1 solution

On the first look, your code seems to be OK. I'll change only this line:
VB
If TypeOf ctr Is System.Windows.Forms.CheckBox Then


BTW: Never use names like: Control, etc as name of variable, because Control[^] defines the base class for controls, which are components with visual representation.

More about TypeOf operator: http://msdn.microsoft.com/en-us/library/0ec5kw18.aspx[^]
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 5-Mar-13 13:55pm    
Maybe it does not work because the code is not recursive. Some check boxes can be deeper in hierarchy, in some panels...
—SA
Maciej Los 5-Mar-13 15:01pm    
You're right. I forgot about it.
Maciej Los 5-Mar-13 15:37pm    
Sergey, if i'm not wrong, making parent control invisible - will do the job ;)
Sergey Alexandrovich Kryukov 5-Mar-13 16:06pm    
I don't quite understand. If you make a parent invisible, children are always invisible. If making it all invisible is the goal, this is the way to go. (One-step, laconic, lean... :-)
If you want to see the child but not the parent, you cannot hide the parent. You rather can fill the parent's client area with the child, for example, they it will behave like only a child is visible...
—SA
Sergey Alexandrovich Kryukov 5-Mar-13 13:58pm    
Also, in .NET, using the name of the variable or member the same as the name of its type is quite fine and even recommended by Microsoft, did you know it? By a good reason: it's a good way of naming if there is only one variable/name of this type...
Maybe I would not do it with a loop variable though.
—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900