代码:

 

 private void button1_Click(object sender, EventArgs e)
        {
            StringBuilder sb = new StringBuilder();
            //遍历窗体上所有控件
            foreach (Control ctr in this.Controls)
            {
                //判断该控件是不是CheckBox
                if (ctr is CheckBox)
                {
                    //将ctr转换成CheckBox并赋值给ck
                    CheckBox ck = ctr as CheckBox;
                    if (ck.Checked)
                    {
                        sb.AppendLine(ck.Text);
                    }
                }

            }
            this.label2.Text = sb.ToString();

        }

winform中CheckBox遍历小例子

 

相关文章:

  • 2022-12-23
  • 2022-02-09
  • 2022-12-23
  • 2021-11-27
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-11-28
  • 2022-12-23
  • 2021-12-16
  • 2022-12-23
  • 2021-12-23
  • 2022-12-23
相关资源
相似解决方案