我需要获取这两个panel中 radiobutton控件的check属性 到主窗体中 如何实现
或者在容器控件选择上是否有其他更好的选择 也可以示下
同一类型的radiobutton的_CheckedChanged 关联同一个处理函数
//.design.cs
this.radioButton1.CheckedChanged += new System.EventHandler(this.radioButton_CheckedChanged);
this.radioButton2.CheckedChanged += new System.EventHandler(this.radioButton_CheckedChanged);
this.radioButton3.CheckedChanged += new System.EventHandler(this.radioButton_CheckedChanged);
//.cs
string selectedItem = null;
private void radioButton_CheckedChanged(object sender, EventArgs e)
{
RadioButton rb = sender as RadioButton ;
if (rb.Checked)
{
selectedItem = rb.Text;
}
}
if (panel1.Controls.OfType<RadioButton>().First(x => x.Checked).Name == "某个名字")
题主是想知道是哪个RadioButton被选中了,想在主界面中输出选中项的信息吗
不妨定义两个字符串变量存储两个panal中RadioButton的信息,checked值不同,分别赋给变量的值不同,没有的话给空字符,然后输出变量的存储值。
最近刚学的,不知这个方法是否适合题主的要求。