动态创建新面板中的groupbox

时间:2017-02-27 15:49:46

标签: vb.net vb.net-2010

我想动态地在新面板中创建groupbox。我是怎么在vb.net中这样做的?谢谢........................

Dim Groups As New Dictionary(Of String, GroupBox)
Dim Panels As New Dictionary(Of String, Panel)
Dim jmlpnl As Integer = 1
Dim jmlgrp As Integer = 10

Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
    Dim pnl As New Panel
    For i As Integer = 1 To jmlpnl
        Me.Controls.Add(pnl)
        pnl.Width = 883
        pnl.Height = 744
        pnl.Top = 5
        pnl.Left = 439
        pnl.BackColor = Color.White
        Panels.Add("Panel" & i, pnl)
        pnl.Tag = "Panel" & i
        For j As Integer = 1 To jmlgrp
           'create groupbox in my new panel
        Next
    Next

End Sub

1 个答案:

答案 0 :(得分:0)

这不是一项非常艰巨的任务。您只需创建新的组框并将其添加到Panel。你必须考虑的唯一事情是分发,这个代码只是将它们放在另一个上,如果你想要一些不同的东西,你需要使用topleft变量:< / p>

Dim top As Integer = 0
Dim left As Integer = 0
For j As Integer = 1 To jmlgrp
    'create groupbox in my new panel
    Dim grp As New GroupBox
    grp.Width = 50
    grp.Height = 50
    grp.Top = top
    grp.Left = left

    pnl.Controls.Add(grp)
    left += 60
Next