您可以使用的Text
属性RadioButton
。
private void button1_Click(object sender, EventArgs e) { if (radioButton1.Checked) { MessageBox.Show("You are playing "+radioButton1.Text); } else if (radioButton2.Checked) { MessageBox.Show("You are playing Maplestory "+"+radioButton2.Text); } else if (radioButton3.Checked) { MessageBox.Show("You are playing League "+"+radioButton3.Text); } }
解决方案2: 没有SelectedItem
可供RadioButton
控制的属性。
但您可以创建一个function
将返回Name
所选的的RadioButton
尝试这个:
private String getSelectedRadioButtonName() { foreach (Control c in groupBox1.Controls) { if (c is RadioButton && ((RadioButton) c).Checked==true) { return c.Text; } } return "No Game"; } private void button1_Click(object sender, EventArgs e) { MessageBox.Show("You are playing "+getSelectedRadioButtonName()); }