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
这篇关于如何将嵌套组框中的单选按钮设置为与该组框外的单选按钮相同的组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何将嵌套组框中的单选按钮设置为与该组框外的单选按钮相同的组
基础教程推荐
- 将 Office 安装到 Windows 容器 (servercore:ltsc2019) 失败,错误代码为 17002 2022-01-01
- MS Visual Studio .NET 的替代品 2022-01-01
- 为什么Flurl.Http DownloadFileAsync/Http客户端GetAsync需要 2022-09-30
- rabbitmq 的 REST API 2022-01-01
- SSE 浮点算术是否可重现? 2022-01-01
- 将 XML 转换为通用列表 2022-01-01
- 如何激活MC67中的红灯 2022-01-01
- c# Math.Sqrt 实现 2022-01-01
- 有没有办法忽略 2GB 文件上传的 maxRequestLength 限制? 2022-01-01
- 如何在 IDE 中获取 Xamarin Studio C# 输出? 2022-01-01