C#中动态增加若干个button个按钮,想要几个可以添加几个
1个回答
展开全部
int count=50;//50个
for (int i = 1 ,x=10, y=10; i <= count; i++)
{
this.btnCancel = new Button();
this.btnCancel.Text = "button-"+i.ToString();
this.Controls.Add(btnCancel);
this.btnCancel.Location = new Point(x, y);
if (x+btnCancel.Width*2+20> this.Width)
{
x = 10;
y += btnCancel.Height+10;
}
else
{
x += btnCancel.Width+10;
}
}
for (int i = 1 ,x=10, y=10; i <= count; i++)
{
this.btnCancel = new Button();
this.btnCancel.Text = "button-"+i.ToString();
this.Controls.Add(btnCancel);
this.btnCancel.Location = new Point(x, y);
if (x+btnCancel.Width*2+20> this.Width)
{
x = 10;
y += btnCancel.Height+10;
}
else
{
x += btnCancel.Width+10;
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询