我有一个表格布局面板,我使用以下代码动态添加行:
attemptstlp.RowCount += 2
attemptstlp.Height = attemptstlp.Height + 62
attemptstlp.RowStyles.Add(New RowStyle(SizeType.Absolute, 30))
(您知道attemptstlp
是panel
)
我正在使用循环来处理添加它们的这些行。我发现一切正常,除了行样式的一半停止应用(所以如果我想添加24行2行,高度将在添加第12批行后停止应用)。
在添加了一半的行之后,是否有人可以提供关于为什么行恢复(我假设)为自动大小的建议。引用此面板的唯一其他代码行是添加文本框的行和用于暂停和恢复布局的行,以帮助减少闪烁和加载时间。
首次创建时,table layout panel
的初始高度为40
,1
行高39
。
提前致谢, mrtechguy
答案 0 :(得分:0)
这适用于在TableLayoutPanel中添加行和控件。试试看。
'Define a blank Tablelayoutpanel with 3 columns in the design page
Dim TableLayoutPanel3 As New TableLayoutPanel()
TableLayoutPanel3.Name = "TableLayoutPanel3"
TableLayoutPanel3.Location = New System.Drawing.Point(32, 287)
TableLayoutPanel3.AutoSize = True
TableLayoutPanel3.Size = New System.Drawing.Size(620, 20)
TableLayoutPanel3.ColumnCount = 3
TableLayoutPanel3.CellBorderStyle = TableLayoutPanelCellBorderStyle.Single
TableLayoutPanel3.BackColor = System.Drawing.Color.Transparent
TableLayoutPanel3.ColumnStyles.Add(New ColumnStyle(SizeType.Percent, 26.34146!))
TableLayoutPanel3.ColumnStyles.Add(New ColumnStyle(SizeType.Percent, 73.65854!))
TableLayoutPanel3.ColumnStyles.Add(New ColumnStyle(SizeType.Absolute, 85.0!))
Controls.Add(TableLayoutPanel3)
'Create a button btnAddRow to add rows on each click
Private Sub btnAddRow_Click(sender As System.Object, e As System.EventArgs) Handles btnAddRow.Click
TableLayoutPanel3.GrowStyle = TableLayoutPanelGrowStyle.AddRows
TableLayoutPanel3.RowStyles.Add(New RowStyle(SizeType.Absolute, 20))
TableLayoutPanel3.SuspendLayout()
TableLayoutPanel3.RowCount += 1
Dim tb1 As New TextBox()
Dim tb2 As New TextBox()
Dim tb3 As New TextBox()
TableLayoutPanel3.Controls.Add(tb1 , 0, TableLayoutPanel3.RowCount - 1)
TableLayoutPanel3.Controls.Add(tb2, 1, TableLayoutPanel3.RowCount - 1)
TableLayoutPanel3.Controls.Add(tb3, 2, TableLayoutPanel3.RowCount - 1)
TableLayoutPanel3.ResumeLayout()
tb1.Focus()
End Sub