Results 1 to 3 of 3

Thread: [RESOLVED] Hiding all controls in a groupbox?

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2009
    Posts
    435

    Resolved [RESOLVED] Hiding all controls in a groupbox?

    Is it possible to hide all controls in a groupbox using code?

  2. #2
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    25,464

    Re: Hiding all controls in a groupbox?

    try this:

    vb Code:
    1. Public Class Form1
    2.  
    3.     Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
    4.         Array.ForEach(Me.GroupBox1.Controls.Cast(Of Control).ToArray, AddressOf hideControls)
    5.     End Sub
    6.  
    7.     Private Function hideControls(ByVal c As Control) As Control
    8.         c.Hide()
    9.         Return c
    10.     End Function
    11.  
    12. End Class

  3. #3
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,299

    Re: Hiding all controls in a groupbox?

    Quote Originally Posted by .paul. View Post
    try this:

    vb Code:
    1. Public Class Form1
    2.  
    3.     Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
    4.         Array.ForEach(Me.GroupBox1.Controls.Cast(Of Control).ToArray, AddressOf hideControls)
    5.     End Sub
    6.  
    7.     Private Function hideControls(ByVal c As Control) As Control
    8.         c.Hide()
    9.         Return c
    10.     End Function
    11.  
    12. End Class
    There's nothing wrong with actually using a loop. Array.ForEach is nice and all but, if you have to write an extra method to make it work, where's the advantage? Just use an actual For Each loop:
    vb.net Code:
    1. For Each ctl As Control In myGroupBox.Controls
    2.     ctl.Hide()
    3. Next
    You could also put a Panel in the GroupBox and all the other controls on the Panel, then just hide the Panel.

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