我有一个包含多个单选按钮的表单,一次只能选择一个。
一些单选按钮已连接,需要通过标题进行解释。为此,我将它们放在一个 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/