以下代码创建动态代码,其控制数量因数据库而异。
FlowLayoutPanel flowlayout = new FlowLayoutPanel();
flowlayout.Dock = DockStyle.Fill;
flowlayout.AutoScroll = true;
while (reader.Read())
{
Button button = new Button();
button.Size = new Size(500, 200);
button.Name = reader["fname"].ToString();
button.Text = reader["userID"].ToString();
button.BackColor = Color.Black;
button.ForeColor = Color.White;
button.Dock = DockStyle.Top;
flowlayout.Controls.Add(button);
}
panel1.Controls.Add(flowlayout);
然后我想将此控件添加到在运行时创建的动态面板控件中。