c# - 如何对 Windows 窗体中的单选按钮组进行分组

标签 c# radio-button windows-forms-designer

我有一个包含多个单选按钮的表单,一次只能选择一个。

一些单选按钮已连接,需要通过标题进行解释。为此,我将它们放在一个 Groupbox 中。但是,组框内的单选按钮不再连接到组框外的单选按钮,并且可以从中选择两个。

有没有办法连接单选按钮,使它们都对彼此使用react?或者有没有更好的方法来分组和解释单选按钮然后使用组框?

最佳答案

这是 RadioButton 的设计行为根据 MSDN 按其容器分组:

When the user selects one option button (also known as a radio button) within a group, the others clear automatically. All RadioButton controls in a given container, such as a Form, constitute a group. To create multiple groups on one form, place each group in its own container, such as a GroupBox or Panel control

您可以尝试为要链接的 RadioButtons 使用通用事件处理程序并自行处理检查/取消检查,或者您可以将 RadioButtons 放在 GroupBox 的顶部,而不是将它们添加到 GroupBox 然后再 BringToFront。

关于c# - 如何对 Windows 窗体中的单选按钮组进行分组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10944679/

相关文章:

c# - 将 BindingSource.DataSource 声明为通用的

C# Windows Forms ListView 获取选中的行值

c# - ASP.NET C# - 使用数据集读取一行?

c# - 在 C# 中使用 Windows 窗体创建多个窗体?

c# - 如何在 Sharepoint Web 部件中将 excel 文件(xlsx 文件)转换为 pdf?

c# - 禁用的RadioButton仍然可以选择

android - radiogroup 的自定义圆形样式

c++ - 使用 Win32 的带有主题的透明单选按钮控件

c# - 如何使用 C# 消除数据表中的重复条目?

c# - 运行 BenchmarkDotNet 时为 "Wrong assembly binding redirects"