如何对 Windows 窗体单选按钮进行分组?
如何对 Windows 窗体应用程序中的单选按钮进行分组(很像 ASP.NET 的单选按钮列表!)?
所以我可以在从选项中选择的每种情况之间进行切换。
How can I group the radio buttons in Windows Form application (a lot like ASP.NET's radiobuttonlist!)?
So I can switch between each case chosen from the options.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(9)
将组的所有单选按钮放入容器对象(例如
Panel
或GroupBox
)中。这将在 Windows 窗体中自动将它们分组在一起。Put all radio buttons for a group in a container object like a
Panel
or aGroupBox
. That will automatically group them together in Windows Forms.查看将单选按钮放置在 GroupBox 中。
Look at placing your radio buttons in a GroupBox.
您应该将组的所有单选按钮放置在同一个容器中,例如
GroupBox
或Panel
。You should place all the radio buttons of the group inside the same container such as a
GroupBox
orPanel
.我喜欢 WPF 中对 RadioButtons 进行分组的概念。有一个属性
GroupName
指定哪些 RadioButton 控件是互斥的 (http://msdn.microsoft.com/de-de/library/system.windows.controls.radiobutton.aspx)。所以我为WinForms编写了一个支持此功能的派生类:
I like the concept of grouping RadioButtons in WPF. There is a property
GroupName
that specifies which RadioButton controls are mutually exclusive (http://msdn.microsoft.com/de-de/library/system.windows.controls.radiobutton.aspx).So I wrote a derived class for WinForms that supports this feature:
不带面板的单选按钮
Radio button without panel
将单选按钮放入 GroupBox(或其他面板)
Put radio buttons inside GroupBox (or other panel)
共享容器内的所有单选按钮默认情况下都位于同一组中。
意味着,如果您检查其中之一 - 其他将不会被检查。
如果要创建独立的单选按钮组,则必须将它们放置到不同的容器中,例如
Group Box
,或者通过代码隐藏控制它们的选中状态嗯>。All radio buttons inside of a share container are in the same group by default.
Means, if you check one of them - others will be unchecked.
If you want to create independent groups of radio buttons, you must situate them into different containers such as
Group Box
, or control their Checked state through code behind.GroupBox
更好。但不仅是组框,甚至您可以使用Panels
(System.Windows.Forms.Panel
)。GroupBox
is better.But not only group box, even you can usePanels
(System.Windows.Forms.Panel
).如果您无法将它们放入一个容器中,则必须编写代码来更改每个 RadioButton 的选中状态:
If you cannot put them into one container, then you have to write code to change checked state of each RadioButton: