单击按钮时动态添加UI元素

时间:2017-12-07 12:29:16

标签: c# visual-studio user-interface

我使用TableLayoutPanel创建了一个简单的Form,下面是一个按钮。 是否可以在每次单击按钮时创建另一个TableLayoutPanel? 我怎样才能填充数据呢? 我搜索了好几个小时但没找到任何东西。

以下是我的表单的截图,如果它可以帮助您:
I want the other tables to appear on the lower half of the split
我希望其他表格出现在分割的下半部分 提前谢谢,Jan

1 个答案:

答案 0 :(得分:1)

当然可以。您可能需要考虑将TableLayoutPanel添加到FlowLayoutPanel,以便它们自动换行和滚动。

只需创建控件,设置列和行,然后将其添加到某个容器中:

TableLayoutPanel tlp = new TableLayoutPanel();
// setup "tlp" with your desired properties
tlp.XXX = YYY
// ...
flowLayoutPanel1.Controls.Add(tlp);