我如何在我的表单中创建动态的 flowlayoutpanels 和 tabpages

how can i create dynamically flowlayoutpanels and tabpages in my form

我需要在我加载的表单中动态地在每个标签页中创建一些 tabpagesflowlayoutpanels。之后我想在每个 flowlayoutpanel.

中添加一些按钮

这是我的代码:

    Public Class Form1
    Dim tabcntrl As New TabControl
    Dim flp(4) As FlowLayoutPanel
    Dim btn As New Button
    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        tabcntrl.Dock = DockStyle.Fill
        tabcntrl.Alignment = TabAlignment.Left
        Me.Controls.Add(tabcntrl)
        For i = 1 To 5
            tabcntrl.TabPages.Add("TAB" & i - 1)
            flp(i - 1).Dock = DockStyle.Fill
            tabcntrl.TabPages(i - 1).Controls.Add(flp(i - 1))
        Next
        button_adding()
    End Sub
    Private Sub button_adding()
        For i = 1 To 5
            For j = 1 To i
                btn.Text = j
                btn.Size = New Size(75, 75)
                btn.Visible = True
                flp(i - 1).Controls.Add(btn)
            Next
        Next
    End Sub
  End Class

在设置FlowLayoutPanelDock属性之前,需要实例化一个FlowLayoutPanel.

...
tabcntrl.TabPages.Add("TAB" & i - 1)
flp(i - 1) = New FlowLayoutPanel    ' <== ADD THIS LINE
flp(i - 1).Dock = DockStyle.Fill
...