if (this.radioButton2.Checked)
{
this.skinEngine1.SkinFile = "EmeraldColor2.ssk";
return;
}
else if (this.radioButton3.Checked) {
this.skinEngine1.SkinFile = "MidsummerColor2.ssk";
return;
}
请问下 如果要转成 switch的话怎么写。 radiobutton 没有 selectvalue属性啊。。
{
this.skinEngine1.SkinFile = "EmeraldColor2.ssk";
return;
}
else if (this.radioButton3.Checked) {
this.skinEngine1.SkinFile = "MidsummerColor2.ssk";
return;
}
请问下 如果要转成 switch的话怎么写。 radiobutton 没有 selectvalue属性啊。。
用switch的话不如直接用if else呢 foreach (RadioButton rad in this.Controls)
{
switch (rad.Name)
{
case "radioButton2":
if (radioButton2.Checked)
{ this.skinEngine1.SkinFile = "EmeraldColor2.ssk";
}
break;
case "radioButton3": }
}
radioButton1.Tag=0;
radioButton2.Tag=1;
radioButton3.Tag=2; foreach (Control mycontrol in this.Controls)
{
if (mycontrol.GetType() == typeof(RadioButton))
{
RadioButton myradio = mycontrol as RadioButton;
int index =(int) myradio.Tag;
if (myradio.Checked == true)
{
this.skinEngine1.SkinFile=skins[index];
break;
}
}
}
=========
用RadioButtonList即可,楼主的例子无须使用switch
RadioButton rbtn = new RadioButton();
rbtn = (RadioButton)(this.rbtn1.Checked ? this.rbtn1 : (this.rbtn2.Checked ? this.rbtn2 : null));
switch(rbtn.Text)
{
case "apple":this.txtFruit.Text = this.rbtn1.Text;
break;
case "pear":this.txtFruit.Text = this.rbtn2.Text;
break;
default:this.txtFruit.Text = "You choose nothing.";
break;
}