110,538
社区成员
发帖
与我相关
我的任务
分享
private void Form1_Load(object sender, EventArgs e)
{
radioButton1.CheckedChanged+=new EventHandler(radioButton1_CheckedChanged);
radioButton2.CheckedChanged += new EventHandler(radioButton1_CheckedChanged);
radioButton3.CheckedChanged+=new EventHandler(radioButton1_CheckedChanged);
radioButton1.Click+=new EventHandler(radioButton1_Click);
radioButton2.Click+=new EventHandler(radioButton1_Click);
radioButton3.Click+=new EventHandler(radioButton1_Click);
radioButton1.Checked = true; //初始选项,也可不设置任何初始选项。
}
RadioButton lastChk;//最后一次选中状态的单选按钮
private void radioButton1_Click(object sender, EventArgs e)
{
RadioButton rad = sender as RadioButton;
if (lastChk != null && lastChk != rad)
{
lastChk.Checked = false;
}
rad.Checked = !rad.Checked;
}
private void radioButton1_CheckedChanged(object sender, EventArgs e)
{
RadioButton rad = sender as RadioButton;
if (rad.Checked)
{
lastChk = rad;
}
}
radiobutton1.Checked = false;