for (int column = 0; column < tableLayoutPanel.ColumnStyles.Count; column++)
{
for (int row = 0; row < tableLayoutPanel.RowStyles.Count; row++)
{
TextBox tb = new TextBox();
tb.Text = "日期";
tb.TextAlign = HorizontalAlignment.Center;
tb.BackColor = Color.FromArgb(241, 231, 202);
tb.BringToFront();
tb.Dock = DockStyle.Top;
tableLayoutPanel.Controls.Add(p, column, row);
}
this.SuspendLayout(); //此处为不闪屏,一定要有的!
}
}
tableLayoutPanel.ColumnStyles.Count为设置好的行号;
上面就是循环动态添加控件的方法,每一个控件里面添加一个TextBox控件;
{
for (int row = 0; row < tableLayoutPanel.RowStyles.Count; row++)
{
TextBox tb = new TextBox();
tb.Text = "日期";
tb.TextAlign = HorizontalAlignment.Center;
tb.BackColor = Color.FromArgb(241, 231, 202);
tb.BringToFront();
tb.Dock = DockStyle.Top;
tableLayoutPanel.Controls.Add(p, column, row);
}
this.SuspendLayout(); //此处为不闪屏,一定要有的!
}
}
tableLayoutPanel.ColumnStyles.Count为设置好的行号;
上面就是循环动态添加控件的方法,每一个控件里面添加一个TextBox控件;