在一个组框groupbox中,放两个radiobox控件,竟然都可以为 Checked = true;
---------------------------------------------------
按理说,同一个组框中,只能有一个 radiobox的checked 为 true 呀,
但是我竟然可以用代码设置两个全为真,或是全为假,这是为什么呢?
private void button1_Click(object sender, EventArgs e)
{
rd1.Checked = true;
rd2.Checked = true;
} private void button2_Click(object sender, EventArgs e)
{
rd1.Checked = false;
rd2.Checked = false;
}
---------------------------------------------------
按理说,同一个组框中,只能有一个 radiobox的checked 为 true 呀,
但是我竟然可以用代码设置两个全为真,或是全为假,这是为什么呢?
private void button1_Click(object sender, EventArgs e)
{
rd1.Checked = true;
rd2.Checked = true;
} private void button2_Click(object sender, EventArgs e)
{
rd1.Checked = false;
rd2.Checked = false;
}
{
rd1.Checked = true;
rd2.Checked = true;
}点击button1之后,
rd1 是未选中,rd2是选中;也就是所以最后一个为准
实在不信,我就发图为证了。
{
public Form1()
{
InitializeComponent();
} private void button1_Click(object sender, EventArgs e)
{
rd1.Checked = false;
rd2.Checked = false;
} private void button3_Click(object sender, EventArgs e)
{
rd1.Checked = true;
rd2.Checked = true;
}
}
是最后一个设置选中语句的那个
rd1 是未选中,rd2是选中;
但是事实上,确实多个可以被选中,这是为什么呢?
难道是 bug
你再试试,ok?
如果是autocheck设置为false 后会出现这样的情况
我回答的时候还没看到你的回复,所以才那样说的。下面是一点我在网上copy的关于这个属性的解释,你看下,也许有用If the AutoCheck property is set to false, a group of RadioButton controls will not act as a mutually exclusive group and the Checked property must be updated in code.
单选当然是能被选中的
1个2个多个都是一样
你ADD进了分组框
但分组框不知道2个按钮是一组
你的明白