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
这篇关于如何将嵌套组框中的单选按钮设置为与该组框外的单选按钮相同的组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何将嵌套组框中的单选按钮设置为与该组框外的单选按钮相同的组
基础教程推荐
- 如果有人提交恶意软件Nuget包怎么办? 2022-01-01
- Moq It.Is<>不匹配 2022-01-01
- WPF 模态进度窗口 2022-01-01
- 我应该在后面的代码中直接使用 Linq To SQL 还是使 2022-01-01
- C# 从 List<List<int>> 中删除重 2022-01-01
- .NET SerialPort DataReceived 事件未触发 2022-01-01
- 禁止输入少量字符,例如'<'、'&a 2022-01-01
- 当值可以是对象或空数组时反序列化 JSON 2022-01-01
- Azure Functions:CosmosDBTrigger 未在 Visual Studio 中触发 2022-01-01
- 如何使用 .Net 检查 Active Directory 服务器是否已启动并正在运行? 2022-01-01
