ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • C# 체크박스
    C#/WindowForm 2022. 3. 30. 02:52

    namespace _019_CheckBox
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }
    
            private void button1_Click(object sender, EventArgs e)
            {
                string checkStates = "";
                CheckBox[] cBox = { checkBox1, checkBox2, checkBox3, checkBox4, checkBox5 };
                foreach (var item in cBox)
                {
                    checkStates += string.Format("{0} : {1}\n", //Format을 사용하여 문자열에 계속 추가
                          item.Text, item.Checked);
                }
                MessageBox.Show(checkStates, "checkStates");
                string summary = string.Format("좋아하는 과일은 : ");
                foreach (var item in cBox)
                {
                    if (item.Checked == true)
                        summary += item.Text + " ";
                }
                MessageBox.Show(summary, "summary");
    
    
            }
        }
    }

     

    실행화면
    첫번째
    두번째

     

    'C# > WindowForm' 카테고리의 다른 글

    ComboBox  (0) 2022.04.06
    C# 라디오버튼과 그룹박스  (0) 2022.03.30
    C# Flag  (0) 2022.03.30
    C# 윈도우 폼 메시지 박스  (0) 2022.03.30
    C# 두개의 폼 띄우기  (0) 2022.03.30

    댓글

Designed by Tistory.