Click here to Skip to main content
15,925,444 members
Home / Discussions / Visual Basic
   

Visual Basic

 
AnswerRe: Can we use label(i) instead of label 1 ? Pin
Abhinav S27-Mar-10 22:41
Abhinav S27-Mar-10 22:41 
GeneralRe: Can we use label(i) instead of label 1 ? Pin
Johan Hakkesteegt27-Mar-10 22:56
Johan Hakkesteegt27-Mar-10 22:56 
GeneralRe: Can we use label(i) instead of label 1 ? Pin
Abhinav S27-Mar-10 23:06
Abhinav S27-Mar-10 23:06 
GeneralRe: Can we use label(i) instead of label 1 ? Pin
Eddy Vluggen28-Mar-10 0:30
professionalEddy Vluggen28-Mar-10 0:30 
GeneralRe: Can we use label(i) instead of label 1 ? Pin
Dave Kreskowiak28-Mar-10 6:09
mveDave Kreskowiak28-Mar-10 6:09 
GeneralRe: Can we use label(i) instead of label 1 ? Pin
Steven J Jowett29-Mar-10 3:26
Steven J Jowett29-Mar-10 3:26 
AnswerRe: Can we use label(i) instead of label 1 ? Pin
Johan Hakkesteegt27-Mar-10 23:00
Johan Hakkesteegt27-Mar-10 23:00 
AnswerRe: Can we use label(i) instead of label 1 ? Pin
Gregory Gadow29-Mar-10 3:50
Gregory Gadow29-Mar-10 3:50 
This is what I would suggest
Private Sub HideLabels(ByRef Ctrl As Control)
    Dim Lbl As Label = Nothing

    For Each C As Control In Ctrl.Controls
        If C.HasChildren Then
            HideLabels(C)
        End If

        Lbl = TryCast(Ctrl, Label)
        If Lbl IsNot Nothing Then Lbl.Visible= False
    Next
End Sub

This tests to see if the control is a Label and, if so, set its Visible property. It also iterates through any child controls. Unlike CType, TryCast will attempt to convert the object and return Nothing if it cannot. Also, note the use if ByRef: you want to make sure you are changing the actual controls and not copies.

The advantage to this technique is that you don't have to worry about what you actually call the labels, so you can give them meaningful names. Just call this method with whatever container control you want, so
HideLabels(Me)
called in a Form would hide every Label on the form. Controls other than labels fail the TryCast and are not affected.
QuestionValue of a variable changing abnormally ! Pin
Razanust27-Mar-10 18:02
Razanust27-Mar-10 18:02 
AnswerRe: Value of a variable changing abnormally ! Pin
Dave Kreskowiak27-Mar-10 18:54
mveDave Kreskowiak27-Mar-10 18:54 
GeneralRe: Value of a variable changing abnormally ! Pin
Razanust27-Mar-10 19:12
Razanust27-Mar-10 19:12 
GeneralRe: Value of a variable changing abnormally ! Pin
Razanust27-Mar-10 19:34
Razanust27-Mar-10 19:34 
QuestionMultiple forms of same look. Pin
Razanust26-Mar-10 8:53
Razanust26-Mar-10 8:53 
AnswerRe: Multiple forms of same look. Pin
KChandos26-Mar-10 11:34
professionalKChandos26-Mar-10 11:34 
GeneralRe: Multiple forms of same look. Pin
Razanust27-Mar-10 10:23
Razanust27-Mar-10 10:23 
GeneralRe: Multiple forms of same look. Pin
Gregory Gadow29-Mar-10 3:58
Gregory Gadow29-Mar-10 3:58 
AnswerRe: Multiple forms of same look. Pin
programmervb.netc++26-Mar-10 17:02
programmervb.netc++26-Mar-10 17:02 
GeneralRe: Multiple forms of same look. Pin
Luc Pattyn26-Mar-10 17:38
sitebuilderLuc Pattyn26-Mar-10 17:38 
AnswerRe: Multiple forms of same look. Pin
Johan Hakkesteegt27-Mar-10 23:05
Johan Hakkesteegt27-Mar-10 23:05 
AnswerRe: Multiple forms of same look. Pin
Deep Unknown29-Mar-10 9:40
Deep Unknown29-Mar-10 9:40 
QuestionNavigating a web site using VB.net code. Pin
Daniel Riek26-Mar-10 5:23
Daniel Riek26-Mar-10 5:23 
AnswerRe: Navigating a web site using VB.net code. Pin
David Mujica26-Mar-10 6:09
David Mujica26-Mar-10 6:09 
QuestionAltering dll reference from in exe in VB.Net Deployment Pin
JayKhatri26-Mar-10 4:32
JayKhatri26-Mar-10 4:32 
AnswerRe: Altering dll reference from in exe in VB.Net Deployment Pin
Dave Kreskowiak26-Mar-10 13:59
mveDave Kreskowiak26-Mar-10 13:59 
QuestionDiscrepency in List tables subroutine Pin
Quecumber25626-Mar-10 4:17
Quecumber25626-Mar-10 4:17 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.