Results 1 to 2 of 2

Thread: Set of all disabled objects

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Oct 2011
    Posts
    152

    Set of all disabled objects

    I need to be able to make the disabled objects in my project invisible and vice-versa. Is there a way I can find a set of all the disabled objects in the project to set them all invisible?

  2. #2
    Hyperactive Member
    Join Date
    Apr 2011
    Location
    England
    Posts
    421

    Re: Set of all disabled objects

    If you mean controls then you can do so using linq provided all your controls are in the same container:
    VB.NET Code:
    1. For Each Ctrl As Control In Me.Controls.OfType(Of Control).Where(Function(c) Not c.Enabled)
    2.     Ctrl.Visible = False
    3. Next Ctrl
    If you have more than one container I would use a loop:
    VB.NET Code:
    1. 'Start the loop on your topmost container i.e. the form.
    2. HideDisabledControls(Me)
    3.  
    4. Private Sub HideDisabledControls(ByVal Parent As Control)
    5.     For Each C As Control In Parent.Controls
    6.         If Not (C.Enabled) Then
    7.             C.Visible = False
    8.         ElseIf C.HasChildren Then
    9.             HideDisabledControls(C)
    10.         End If
    11.     Next C
    12. End Sub
    To Show the enabled controls you just do the opposite.

    HTH

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width