我想动态创建tableLayout面板。
我已经实现了这个,但我的列大小是固定的,但是行大小是动态添加的 - 所以如何添加与高度相同的每一行?
假设我有
如何逐个动态添加?
radiobutton1 label1
radiobutton1 label1
是那样的?
这是我的动态表格代码
Dim dynamictablelayout As New TableLayoutPanel
Private Sub dynamictable(ByVal rowcount As Integer)
Me.dynamictablelayout.ColumnCount = 2
Me.dynamictablelayout.ColumnStyles.Add(New System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 8.333333!))
Me.dynamictablelayout.ColumnStyles.Add(New System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 91.66666!))
Me.dynamictablelayout.Location = New System.Drawing.Point(0, 3)
'Me.dynamictablelayout.Name = "TableLayoutPanel1"
Me.dynamictablelayout.RowCount = rowcount
For i As Integer = 0 To dynamictablelayout.RowCount - 1 Step 1
Me.dynamictablelayout.RowStyles.Add(New System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent))
Me.dynamictablelayout.Height = 100
Next
Me.dynamictablelayout.AutoSize = True
Me.dynamictablelayout.Size = New System.Drawing.Size(417, 454)
Me.dynamictablelayout.TabIndex = 0
Me.dynamictablelayout.AutoScroll = True
Me.dynamictablelayout.Anchor = AnchorStyles.None
Me.dynamictablelayout.BackColor = Color.Violet
Me.dynamictablelayout.RowStyles.Clear()
Me.dynamictablelayout.ColumnStyles.Clear()
Me.dynamictablelayout.CellBorderStyle = System.Windows.Forms.TableLayoutPanelCellBorderStyle.OutsetDouble
Me.pnlemail.ResumeLayout(False)
pnlemail.Controls.Add(dynamictablelayout)
End Sub
这是我的放置控制码
Dim i as integer=0
Private Sub placedynamiccontrol()
For Each email As String In Arremailslist
rb.Name = "rb" & email
TableLayoutPanel1.Controls.Add(rb, 0, i)
lbl.Name = "lbl" & email
lbl.Text = email
lbl.Size = New System.Drawing.Size(500, 15)
dynamictablelayout.Controls.Add(lbl, 1, i)
i = i + 1
Next
End Sub
但是我无法正确放置控件,而且我还需要scrollBar
请帮帮我
答案 0 :(得分:0)
您可以使用TableLayoutPanel和SetColumn方法在SetRow内明确设置子控件的列和行:
Protected Overrides Sub OnLoad(e As EventArgs)
MyBase.OnLoad(e)
dynamicTable.ColumnCount = 2
dynamicTable.RowCount = 5
For i = 0 To 4
Dim label = New Label()
label.Text = i.ToString()
dynamicTable.SetColumn(label, 0)
dynamicTable.SetRow(label, i)
dynamicTable.Controls.Add(label)
Next
End Sub