C#/WindowForm

C# 라디오버튼과 그룹박스

hyun0229 2022. 3. 30. 03:22

namespace _019_RadioBT
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {

            string result = "";
            if (rb_Korea.Checked) //rb_Korea.Checked 체크되있으면 True값을 리턴
                result += "국적 : 대한민국\n";
            else if (rb_China.Checked)
                result += "국적 : 중국\n";
            else if (rb_Japan.Checked)
                result += "국적 : 일본\n";
            else if (rb_Others.Checked)
                result += "국적 : 그 외의 국가\n";
            
            if (rb_Male.Checked)
                result += "성별 : 남성";
            else if (rb_Female.Checked)
                result += "성별 : 여성";

            MessageBox.Show(result, "Result");

        }
    }
}

실행화면