这是我的单选按钮
Runescape
Maplestory
League
所以这是我目前的方法,它运行得非常好。
private void button1_Click(object sender, EventArgs e)
{
if (radioButton1.Checked)
{
MessageBox.Show("You are playing Runescape.");
}
else if (radioButton2.Checked)
{
MessageBox.Show("You are playing Maplestory.");
}
else if (radioButton3.Checked)
{
MessageBox.Show("You are playing League.");
}
}
我想知道是否有一种方法可以打印出类似于组合框的SelectedItem。基本上,单选按钮的文本。
Combobox版本:
private void button1_Click(object sender, EventArgs e)
{
MessageBox.Show("You are playing " + comboBox1.SelectedItem);
}
有些事情(不确定是否可能)。
MessageBox.Show("You are playing " + RadioButton.SelectedItem);
答案 0 :(得分:4)
您可以使用Text
的{{1}}属性。
RadioButton
解决方案2: 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);
}
}
控件没有SelectedItem
属性。
但您可以创建一个RadioButton
,它会返回所选function
的{{1}}
试试这个:
Name