我动态创建多个checkbox 规定好一行显示的个数,但是在checkbox总的个数不确定下,我不知道怎样分行显示checkbox,请帮帮我,多谢啦!

解决方案 »

  1.   

    CheckBox.Location=new Point(?,?)   ....
      

  2.   

            int chkwidth = 80;//
            int chkheight = 20;
            int noofeachline = 3;//没行个数
            int noofcheck = 13;//总个数
            private void button1_Click(object sender, EventArgs e)
            {
                for (int i = 0; i < noofcheck; i++)
                {
                    CheckBox tmchk = new CheckBox();
                    tmchk.Text = "check" + i.ToString();
                    tmchk.Left = (i % noofeachline) * 80 + 5;
                    tmchk.Top = (int)(i / noofeachline) * 20 + 5;
                    tmchk.Width = chkwidth;
                    this.Controls.Add(tmchk);
                }
            }
      

  3.   


            int chkwidth = 80;//宽
            int chkheight = 20;//高
            int noofeachline = 3;//没行个数
            int noofcheck = 13;//总个数
            int tmint = 8;//行间距 和 列间距
            private void button1_Click(object sender, EventArgs e)
            {
                for (int i = 0; i < noofcheck; i++)
                {
                    CheckBox tmchk = new CheckBox();
                    tmchk.Text = "check" + i.ToString();
                    tmchk.Left = (i % noofeachline) * chkwidth + tmint;
                    tmchk.Top = (int)(i / noofeachline) * chkheight + tmint;
                    tmchk.Width = chkwidth;
                    tmchk.Height = chkheight;
                    this.Controls.Add(tmchk);
                }
            }