gpt4 book ai didi

c# - 在flowlayoutpanel中动态添加控件

转载 作者:IT王子 更新时间:2023-10-29 04:21:34 24 4
gpt4 key购买 nike

在 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);
}

如何在 FlowLayoutPanel 中动态添加控件?

最佳答案

对于 FlowLayoutPanel ,您无需指定 .Location,因为控件已为您安排好:

Represents a panel that dynamically lays out its contents horizontallyor vertically. ... The FlowLayoutPanel control arranges its contentsin a horizontal or vertical flow direction. Its contents can bewrapped from one row to the next, or from one column to the next.

只需将“flowLayoutPanel1”更改为您的FlowLayoutPanel 的名称:

for (int i = 0; i < 5; i++)
{
Button button = new Button();
button.Tag = i;
flowLayoutPanel1.Controls.Add(button);
}

关于c# - 在flowlayoutpanel中动态添加控件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16900522/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com