日期:2014-05-18  浏览次数:20849 次

RadioButton选中时,触发什么控件
在做一个winform窗体的项目,Form表单上有3个RadioButton,和一个Label,我想做成这样,当选中第一个radiobuttion时,Label.text=first,当选中第二个radiobutton时,Label.text=second。。。。

应该怎么做?

------解决方案--------------------
双击第一个radiobuttion:
在事件里面写:
Label.text=first
双击第二个radiobuttion:
在事件里面写:
Label.text=second
------解决方案--------------------
C# code

if(RadioButton1.Checked)
   Label.Text = first
else if(RadioButton2.Checked)
   Label1.Text = second
else if(RadioButton3.Checked)
   Label1.Text = third
else 
   ...

------解决方案--------------------
将3个RadioButton的CheckedChanged都绑定到下面的radioButton_CheckedChanged事件上。
C# code

        private void radioButton_CheckedChanged(object sender, EventArgs e)
        {
            RadioButton rb = sender as RadioButton;
            if (rb.Text == "radioButton1")
                this.label1.Text = "first";
            else if (rb.Text == "radioButton2")
                this.label1.Text = "secord";
            else if (rb.Text == "radioButton3")
                this.label1.Text = "three";

        }

------解决方案--------------------
同意LS和LSS的 我一般将3个RadioButton的click事件调用同一方法 方法里面同LSS
 if(RadioButton1.Checked)
Label.Text = first
else if(RadioButton2.Checked)
Label1.Text = second
else if(RadioButton3.Checked)
Label1.Text = third

------解决方案--------------------
private void radioButton1_CheckedChanged(object sender, EventArgs e)
{
if (radioButton1.Checked)
{
label1.Text = "first";
}
}

private void radioButton2_CheckedChanged(object sender, EventArgs e)
{
if (radioButton2.Checked)
{
label1.Text = "second";
}
}
------解决方案--------------------
C# code

        private void radioButton1_CheckedChanged(object sender, EventArgs e)
        {
            if (radioButton1.Checked)
            {
                label1.Text = "first";
            }
        }

        private void radioButton2_CheckedChanged(object sender, EventArgs e)
        {
            if (radioButton2.Checked)
            {
                label1.Text = "second";
            }
        }

------解决方案--------------------
探讨
C# code

if(RadioButton1.Checked)
Label.Text = first
else if(RadioButton2.Checked)
Label1.Text = second
else if(RadioButton3.Checked)
Label1.Text = third
else
...

------解决方案--------------------
private void radioButton1_CheckedChanged(object sender, EventArgs e)
{
if (radioButton1.Checked)
{
label1.Text = "first";
}
}