如图有3个选项我选择一个点确定就会弹出提示 弹出的内容就是我选项上的内容 现在我就是不知道怎么弹出提示if... else里就是不知道该怎么写

解决方案 »

  1.   

     if (radioButton1.Checked)
                {
                    MessageBox.Show(radioButton1.Text.ToString());
                }
      

  2.   


    private void button1_Click(object sender, EventArgs e)
            {
                foreach (Control control in groupBox1.Controls)
                {
                    if (((RadioButton)control).Checked)
                    {
                        MessageBox.Show(((RadioButton)control).Text);
                    }
                }
            }
      

  3.   

    用control就可以实现了,不用繁琐的使用if...else语句。
    如果gropbox1中有其它控件,那就需要加上try...catch捕获异常private void button1_Click(object sender, EventArgs e)
            {
                foreach (Control control in groupBox1.Controls)
                {
                    try
                    {
                        if (((RadioButton)control).Checked)
                        {
                            MessageBox.Show(((RadioButton)control).Text);
                        }
                    }
                    catch (Exception)
                    {                    continue;
                    }
                }
            }
      

  4.   


    如果(单选按钮 == 被选中了)
    {
        弹出你选择的内容
    }if(radioButton.Checked == true)
    {
        MessageBox.Show(radioButton.Text);
    }
      

  5.   

    private void button1_Click(object sender, EventArgs e)
            {
                foreach (Control control in groupBox1.Controls)
                {
                    if (((RadioButton)control).Checked)
                    {
                        MessageBox.Show(((RadioButton)control).Text);
                    }
                }
            }
      

  6.   

    if (radioButton1.Checked)
       {
          MessageBox.Show(radioButton1.Text.ToString());
       }
      

  7.   


    var radioText = Controls.Cast<RadioButton>().First(rdo => rdo.Checked).Text;
    MessageBox.Show(radioText);