【问题标题】:Is there any property in the GroupBox that indicates that nested controls were checked?GroupBox 中是否有任何属性表明已检查嵌套控件?
【发布时间】:2012-11-13 10:48:13
【问题描述】:

我在表单页面 (WinForms) 上使用 GroupBox 控件。

GroupBox 包含五个控件(RadioButtons)。

是否知道组框控件是否包含指示控件内的任何按钮是否被选中的属性?

【问题讨论】:

    标签: c# .net winforms


    【解决方案1】:

    不,因为 GroupBox 不仅仅适用于 RadioButtons。它是一个通用的容器控件。要检查是否检查了任何内容,您可以在一行中使用Linq

    bool anyChecked = gb.Controls.OfType<RadioButton>().Any(rb => rb.Checked);
    

    或者,您可以使用它创建自己的扩展方法,如果经常重复使用,则可以轻松调用它。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-01-07
      • 2013-03-31
      • 1970-01-01
      • 2014-04-04
      • 2022-06-30
      • 2014-02-17
      相关资源
      最近更新 更多