Lyn Lyn -4 years ago 95 Question

create groupbox in new panel dynamically

I want to create groupbox in my new panel dynamically. How i do this in 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
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

End Sub

Answer Source

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

    left += 60
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download