110,567
社区成员
发帖
与我相关
我的任务
分享
private void CreateButton()
{
int buttonW = 50;//button 宽度
int buttonH = 24;//button 高度
int hCount = 3;//每行几个
int yCount = 2;//多少行
int hGop = (this.panel1.Width - buttonW * hCount) / (hCount + 1);
int yGop = (this.panel1.Height - buttonH * yCount) / (yCount + 1);
for (int j = 0; j < yCount; j++)
{
for (int i = 0; i < hCount; i++)
{
Button button = new Button();
button.Size = new Size(buttonW, buttonH);
Point p = new Point();
p.X = hGop * (i + 1) + i * buttonW;
p.Y = yGop * (j + 1) + j * buttonH;
button.Location = p;
button.Text = j + "," + i;
this.panel1.Controls.Add(button);
}
}
}