this.groupBox1.Controls.Add(this.checkBox5); this.groupBox1.Controls.Add(this.checkBox4); this.groupBox1.Controls.Add(this.checkBox3); this.groupBox1.Controls.Add(this.checkBox2); this.groupBox1.Controls.Add(this.checkBox1);
private List<CheckBox> prefectures = new List<CheckBox>(); private List<CheckBox> checkBoxes; public Form1() { InitializeComponent(); checkBoxes = groupBox1.Controls.OfType<CheckBox>().ToList(); checkBoxes.ForEach(c => c.CheckedChanged += (sende, e) => { prefectures.Remove(c); if (c.Checked) { prefectures.Add(c); } }); } private void button1_Click(object sender, EventArgs e) { txttorikomi.Text = string.Join(" ", prefectures.Select(c => c.Text)); }