在TableLayoutPanel中动态添加控件

时间:2019-12-06 04:17:21

标签: c# winforms tablelayoutpanel toolbox

我正在尝试使用winform复制此excel表:

Excel Sample

// TableLayoutPanel Initialization
   TableLayoutPanel panel = new TableLayoutPanel();
   panel.ColumnCount = 14;
   panel.RowCount = 2;
   panel.Controls.Add(new Textbox() { Text = "Address" }, 1, 0);
   panel.Controls.Add(new Textbox() { Text = "Contact No" }, 2, 0);
   panel.Controls.Add(new Textbox() { Text = "Email ID" }, 3, 0);

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

如何在TableLayoutPanel中动态添加控件,同时保留所有textbox控件并遍历每条记录?

0 个答案:

没有答案