Search code examples
c#vb.netwinformsdesktop-application

How to hidden the GroupBox when Select one of radio button in another GroupBox?


GM everybody,

I've work on WinForms using Vb.net

I want to hide all components inside the groupbox2 when I checked radio button that inside groupbox1

I need to know what is the name of event and where to select it from radio button or from groupbox


Solution

  • If you want to hide the whole groupbox itself:

    Sub SomeRadioButton_CheckedChanged(sender As Object, e as EventArgs) Handles SomeRadioButton.CheckedChanged
      GroupBox2.Visible = Not SomeRadioButton.Checked
    End Sub
    

    If you want to hide the controls inside but leave an empty groupbox:

    Sub SomeRadioButton_CheckedChanged(sender As Object, e as EventArgs) Handles SomeRadioButton.CheckedChanged
      GroupBox2.Controls.ToList().ForEach(Function(c) c.Visible = Not SomeRadioButton.Checked)
    End Sub