简体   繁体   English

动态创建新面板中的groupbox

[英]create groupbox in new panel dynamically

I want to create groupbox in my new panel dynamically. 我想动态地在我的新面板中创建groupbox。 How i do this in vb.net? 我是怎么在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. 您只需创建新的组框并将其添加到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: 你必须考虑的唯一事情是分布,这个代码只是将它们放在另一个上,如果你想要一些不同的东西,你需要使用topleft变量:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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