【问题标题】:How to hidden the GroupBox when Select one of radio button in another GroupBox?在另一个 GroupBox 中选择一个单选按钮时如何隐藏 GroupBox?
【发布时间】:2022-01-12 12:11:12
【问题描述】:

GM 大家,

我使用 Vb.net

处理 WinForms

当我选中 groupbox1 内的单选按钮时,我想隐藏 groupbox2 内的所有组件

我需要知道事件的名称是什么以及从单选按钮或组框中选择它的位置

【问题讨论】:

  • 您想隐藏分组框本身还是将其保留在那里并使其看起来像一个空方格?
  • @CaiusJard 我想将其保留为空方格
  • "I want to hide all components inside the groupbox2 when I checked radio button that inside groupbox1" When ANY RadioButton in the GroupBox is selected, or when a SPECIFIC RadioButton is selected?此外,如果在表单加载时除了 RadioButtons 之外没有其他控件获得焦点,那么至少一个 RadioButton 将自动被选中。

标签: c# vb.net winforms desktop-application


【解决方案1】:

如果你想隐藏整个 groupbox 本身:

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

如果你想隐藏里面的控件但留下一个空的分组框:

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

【讨论】:

    猜你喜欢
    • 2019-06-16
    • 2013-10-19
    • 1970-01-01
    • 2013-01-29
    • 2016-09-24
    • 2015-01-07
    • 2013-01-19
    • 2020-01-21
    • 2023-03-03
    相关资源
    最近更新 更多