110,537
社区成员
发帖
与我相关
我的任务
分享
/// 动态创建button
/// </summary>
// bool b = false;
private void CreateButton()
{
// b = true;
// this.Controls.Clear();
//Variety var = new Variety();
// var.StrNO = "111111";
// DataTable dt = VarietyDAL.GetDataTable(var);
int x = 35;
int y = 25;
for (int i = 0; i < 100; i++)
{
Button btn = new Button();
btn.Size = new System.Drawing.Size(75, 69);
btn.Name = i.ToString();
btn.Text = i.ToString();
//动态创建X,Y坐标,满屏时跳下一行
btn.Location = new System.Drawing.Point(x, y);
if (x > 1024)
{
x = 35;
y += 75;
btn.Location = new System.Drawing.Point(x, y);
}
x += btn.Width + 35;
this.Controls.Add(btn);
}
}
public Form1()
{
InitializeComponent();
this.DoubleBuffered = true;
}
/// 动态创建button
/// </summary>
// bool b = false;
private void CreateButton()
{
// b = true;
// this.Controls.Clear();
//Variety var = new Variety();
// var.StrNO = "111111";
// DataTable dt = VarietyDAL.GetDataTable(var);
int x = 35;
int y = 25;
this.SuspendLayout();
Button[] buttons = new Button[100];
for (int i = 0; i < 100; i++)
{
buttons[i] = new Button();
buttons[i].Size = new System.Drawing.Size(75, 69);
buttons[i].Name = i.ToString();
buttons[i].Text = i.ToString();
//动态创建X,Y坐标,满屏时跳下一行
buttons[i].Location = new System.Drawing.Point(x, y);
if (x > 1024)
{
x = 35;
y += 75;
buttons[i].Location = new System.Drawing.Point(x, y);
}
x += buttons[i].Width + 35;
}
this.Controls.AddRange(buttons);
this.ResumeLayout();
}