运行时RadioButtons不是独家的 [英] Runtime RadioButtons Are Not Exclusive

查看:55
本文介绍了运行时RadioButtons不是独家的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正忙着在运行时创建控件,只是为了好玩。



我用它来删除表单上的用户控件。用户控件具有Label,RadioButton和TextBox。没什么大不了的。



I'm playing around with creating controls at runtime, just for fun.

I used this to drop a usercontrol on a form. The user control has a Label, a RadioButton, and a TextBox. No biggie.

int ControlsOnPanel = 0;
Panel pnl = new Panel();
pnl.Left = 5;
pnl.Top = ControlsOnPage * 21;
pnl.BorderStyle = BorderStyle.None;
pnl.BackColor = Color.AliceBlue;
for (int i = 1; i <= numRadioButtons.Value; i++)
{
    ControlsOnPage += 1;
    ControlsOnPanel += 1;
    EditableRadioButton rb = new EditableRadioButton();
    rb.Margin = new Padding(7);
    rb.RadioButtonText = "Type text here";
    rb.RadioButtonLabel = ControlsOnPage.ToString() + ".";
    rb.Top = (ControlsOnPanel * 21);
    rb.Left = 0;
    rb.Parent = pnl;
    pnl.Controls.Add(rb);
    pnl.Height = rb.Top+21;
}
pnlTarget.Controls.Add(pnl);





它将EditableRadioButtons添加到Panel(pnl)就好了,然后将该面板放入另一个面板中。 br />


但RadioButtons不像RadioButtons那样。我可以点击所有这些,然后点击它们。



我错过了什么?或者是因为RadioButton在UserControl中,因此在该控件中已经是独占的,并且将它与其他人一起放在Panel上会不会有什么区别? :(



and it adds the EditableRadioButtons to the Panel (pnl) just fine, then puts that panel inside another one.

But the RadioButtons don't act like RadioButtons. I can click all of them and they stay clicked.

What did I miss? Or is it because the RadioButton is inside a UserControl and therefore is already exclusive within that control, and dropping it on a Panel with others won't make a bit of difference? :(

推荐答案

要让一些单选按钮互斥,你必须将它们全部放在同一容器控件中,例如 GroupBox Panel TabPage 。这些集合的部分不应该有任何不同的控件,它们都应该有相同的父级。

如果你有另一组单选按钮,也是互斥的,但与另一个独立,它们是独立的必须有一个父容器。



-SA
To have some set of radio buttons mutually exclusive, you have to put them all in the same container control, such as GroupBox, Panel or TabPage. The parts of these sets should not have any different Parent control, they all should have the same parent.
If you have another set of radio buttons, also mutually exclusive, but independent from another one, they have to have a parent container.

—SA


这篇关于运行时RadioButtons不是独家的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆