简体   繁体   中英

create groupbox in new panel dynamically

I want to create groupbox in my new panel dynamically. How i do this in vb.net? thank you.......................

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

That's a not very difficult task. You just have to create the new groupboxes and add them to the Panel. The only thing you must have in mind is the distribution, this code just puts them one right to the other, if you want something different you'll need to play with the top and left variables:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM