创建Form,在Form添加Panel,最后在panel上动态添加butto
int ytmp = 1; //确定button的Y坐标系
int xtmp = 0; //确定button的X坐标系
int ntmp = 5; //到第几个button开始换行
for (int i = 1; i < 20; i++)
{
int x = 300, y =200; //定义button Location的初始位置
int n = i % ntmp; //取余 如果为0 则换行
xtmp++;
if (n == 0)
{
ytmp++; //Y坐标系数加1
xtmp = 1; //X坐标系数初始化
ntmp += 4; //重新计算换行
}
x = xtmp * x;
y = ytmp * y;
ButtonX btx = new ButtonX();
btx.Size = new Size(200, 150);
btx.Text = "btx: " + i;
btx.BackColor = Color.Transparent;
btx.HotTrackingStyle = eHotTrackingStyle.None;
//设置button圆角
btx.Shape = new DevComponents.DotNetBar.RoundRectangleShapeDescriptor(10);
btx.Location = new Point(x, y);
btnPan.Controls.Add(btx);
}
版权声明:本文为qq_42910382原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。