How to set radio buttons in a nested group box as a same group with radio buttons outside of that group box(如何将嵌套组框中的单选按钮设置为与该组框外的单选按钮相同的组)
问题描述
我有 winform 应用程序 (.NET 4.0)
I have winform application (.NET 4.0)
有没有办法手动设置一组单选按钮?
Is there any way to manually set a group of radio buttons?
我有四个单选按钮,其中两个在组框内,另外两个在该框外.如何将它们全部设置到同一个组?
I have four radio buttons, two of them inside of a group box and the other two outside of that box. How can I set all of them to the same group?
推荐答案
这可能已经在另一个帖子中回答了,听起来一样:
This might have been answered in another post, it sounds the same:
将 Windows 窗体单选按钮分组到不同的父级C#中的控件
这是公认的解决方案:
恐怕您将不得不手动处理此问题...还不错实际上,您可能只需将所有 RadioButton 存储在一个列表中,并为所有这些使用单个事件处理程序:
I'm afraid you'll have to handle this manually... It's not so bad actually, you can probably just store all the RadioButton in a list, and use a single event handler for all of them:
private List<RadioButton> _radioButtonGroup = new List<RadioButton>();
private void radioButton_CheckedChanged(object sender, EventArgs e)
{
RadioButton rb = (RadioButton)sender;
if (rb.Checked)
{
foreach(RadioButton other in _radioButtonGroup)
{
if (other == rb)
{
continue;
}
other.Checked = false;
}
}
}
这是另一个问同样问题的问题:不同面板中的单选按钮组
Here's another question asking the same thing: Radiobuttons as a group in different panels
这篇关于如何将嵌套组框中的单选按钮设置为与该组框外的单选按钮相同的组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何将嵌套组框中的单选按钮设置为与该组框外的单选按钮相同的组


基础教程推荐
- 首先创建代码,多对多,关联表中的附加字段 2022-01-01
- 如何动态获取文本框中datagridview列的总和 2022-01-01
- JSON.NET 中基于属性的类型解析 2022-01-01
- 将事件 TextChanged 分配给表单中的所有文本框 2022-01-01
- 在 VS2010 中的 Post Build 事件中将 bin 文件复制到物 2022-01-01
- 错误“此流不支持搜索操作"在 C# 中 2022-01-01
- 是否可以在 asp classic 和 asp.net 之间共享会话状态 2022-01-01
- 从 VS 2017 .NET Core 项目的发布目录中排除文件 2022-01-01
- 全局 ASAX - 获取服务器名称 2022-01-01
- 经典 Asp 中的 ResolveUrl/Url.Content 等效项 2022-01-01