Kar*_*ski 25 c# dynamic-controls flowlayoutpanel winforms
在Windows窗体中,我可以通过执行以下操作动态添加控件:
for (int i = 0; i < 5; i++)
{
Button button = new Button();
button.Location = new Point(160, 30 * i + 10);
button.Tag = i;
this.Controls.Add(button);
}
Run Code Online (Sandbox Code Playgroud)
如何动态添加控件FlowLayoutPanel?
Idl*_*ind 41
对于a FlowLayoutPanel,您无需指定位置,因为为您安排了控件.只需将" flowLayoutPanel1" 更改为您的姓名FlowLayoutPanel:
for (int i = 0; i < 5; i++)
{
Button button = new Button();
button.Tag = i;
flowLayoutPanel1.Controls.Add(button);
}
Run Code Online (Sandbox Code Playgroud)