int n = 0;
            int m = 0;
            int top = 6;
            Button[] button_area = new Button[53];
            DataSet ds = new DataSet();
            ds = dbconn.selectArea();  //重数据库读去按照使用率排列的省名            this.textBox1.Text = "";
            this.Card = "";            // 动态添加按钮并根据使用情况排列顺序按钮
            for (int i = 0; i < 53; i++)
            {
                button_area[i] = new Button();
                //button_area[i].BackColor = System.Drawing.Color.White;
                if (i == 0 | i == 24 | i == 48)
                {
                    button_area[i].Location = new System.Drawing.Point(top, 20);
                    m = 0;
                    n = 0;
                }
                else
                {                    if (i % 4 == 0)
                    {
                        n++;
                        m = 0;
                        button_area[i].Location = new System.Drawing.Point(top + m * 45, 20 + n * 42);
                    }
                    else
                    {
                        m++;
                        button_area[i].Location = new System.Drawing.Point(top + m * 45, 20 + n * 42);
                    }
                }
                button_area[i].Font = new System.Drawing.Font("宋体", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
                button_area[i].Size = new System.Drawing.Size(37, 36);
                button_area[i].TabIndex = i + 5;
                button_area[i].UseVisualStyleBackColor = true;
                button_area[i].Text = ds.Tables[0].Rows[i][0].ToString();
                button_area[i].Click += new EventHandler(button_area_Click);
                this.Controls.Add(button_area[i]);   
            }可以参考这个例子!

解决方案 »

  1.   

    参考"窗体设计器生成的代码"
     this.label4 = new System.Windows.Forms.Label();
              this.label4.Location = new System.Drawing.Point(176, 120);
                this.label4.Name = "label4";
                this.label4.Size = new System.Drawing.Size(104, 16);
                this.label4.TabIndex = 7;
                this.label4.Text = "已经收到的内容:";
                this.Controls.Add(this.label4);