int rows = 3;//行
int cells = 4;//列
for (int j = 0; j < rows; j++)
{
for (int i = 0; i < cells; i++)
{
Button btn = new Button();
btn.Name = “btns” + i + j;
btn.Size = new Size(panel1.Width / cells, panel1.Height / rows);
btn.Location = new Point( i * btn.Width, j * btn.Height);
btn.Visible = true;
btn.Font = new System.Drawing.Font(“宋体”, 15);
btn.Text = “” + j + “” + i;
btn.BackColor = Color.Green;
btn.Tag = “” + j + “” + i;
btn.Enabled = true;
//btn.MouseDown += new System.Windows.Forms.MouseEventHandler();
//btn.MouseUp += new System.Windows.Forms.MouseEventHandler();
this.panel1.Controls.Add(btn);
}
}
关于在panel控件中添加单元格按钮的学习
最新推荐文章于 2023-06-08 17:06:12 发布