Group, you were very helpful to me in adding multiple textboxes, labels, etc., in my original post. If you would like to read through that, see http://www.daniweb.com/software-development/vbnet/threads/447985/creating-multiple-labels-textboxes-etc.-dynamically#post1934799.

In a similar vein, I now want to dynamically add these multiple panels within a "main" panel, one at a time, with the use of a button control.

I have created the first panel within the main panel on the form itself. Using the code the group and I developed in the original post (see the link above), I have the program generating the additional, identical forms. That code looks like this:

Private Sub btnCreateNewLine_(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCreateNewLine.Click

        Dim b As String = Short.Parse(a)

        'This creates the label "Part No."

        Dim lblPrtNo As New Label()
        lblPrtNo.Name = "lblPrtNo" & Convert.ToString(b)
        lblPrtNo.Text = "Part Number"
        lblPrtNo.ForeColor = Color.White
        lblPrtNo.Font = New Font("Sans Serif", 9)
        lblPrtNo.Font = New Font(lblPrtNo.Font, FontStyle.Regular)
        lblPrtNo.Location = New Point(13, 8)
        lblPrtNo.Size = New Size(77, 15)
        'This generates the textbox for the user to enter the Part No.
        Dim txbPartNo As New TextBox()
        txbPartNo.Name = "txbPartNo" & Convert.ToString(b)
        txbPartNo.Text = ""
        txbPartNo.ForeColor = Color.Black
        txbPartNo.BackColor = Color.Yellow
        txbPartNo.Font = New Font("Sans Serif", 10)
        txbPartNo.Font = New Font(txbPartNo.Font, FontStyle.Bold)
        txbPartNo.Location = New Point(16, 26)
        txbPartNo.Size = New Size(263, 22)
        txbPartNo.Cursor = Cursors.Hand
        txbPartNo.AcceptsReturn = True
        txbPartNo.AcceptsTab = True
        txbPartNo.TabIndex = 10
        AddHandler txbPartNo.TextChanged, AddressOf txbPartNo_Textchanged
        ' This generates the button control to do a part number search
        Dim btnPartNoSearch As New Button()
        btnPartNoSearch.Name = "btnPartNoSearch"
        btnPartNoSearch.Text = "S"
        btnPartNoSearch.FlatStyle = FlatStyle.Popup
        btnPartNoSearch.FlatAppearance.BorderColor = Color.Black
        btnPartNoSearch.FlatAppearance.BorderSize = 2
        btnPartNoSearch.Cursor = Cursors.Hand
        btnPartNoSearch.TabIndex = 11
        btnPartNoSearch.ForeColor = Color.White
        btnPartNoSearch.BackColor = Color.Red
        btnPartNoSearch.Size = New Size(26, 23)
        btnPartNoSearch.Location = New Point(285, 26)
        btnPartNoSearch.Visible = True

        'This creates the Panel and sets the labels and Textboxes to be displayed.
        Dim pnlOrderLine As New Panel()
        pnlOrderLine.Size = New Size(1577, 122)
        pnlOrderLine.Location = New Point(12, x)
        pnlOrderLine.BorderStyle = BorderStyle.Fixed3D
        pnlOrderLine.ForeColor = Color.White
        pnlOrderLine.Visible = True

        Private Sub txbPartNo_Textchanged(ByVal sender As System.Object, ByVal e As EventArgs)
        Dim txbPartNo As TextBox = DirectCast(sender, TextBox)
        Me.Text = txbPartNo.Name & ": " & txbPartNo.Text

Now the challenge is to get the second panel (remember, the first was created on the form) to display within this main panel that I am calling "pnlMainPanel". To do this, my assumption is that I use similar logic as we did to "copy" the original panel. So I wrote this"

 ' This set the order line panel within the main panel
        Dim pnlMainPanel As New Panel()
        pnlMainPanel.Visible = True

Unfortunately, the subsequent panels are created, but they are outside and behind this "main" panel. How do I get these inside the main panel?

In advance, thanks for all the assistance.


4 Years
Discussion Span
Last Post by doncwilson_1

Hi you have added the panel twice once to the Main panel and once to the form:

 'Adding to main panel
 pnlMainPanel.Visible = True
 'Adding to Form i.e. me

Mr. Waddell,

I inserted the code you wrote and tested it. It continues to create the "pnlOrderLine" outside and behind the main panel (pnlMainPanel).

It's back to the drawing board.

Thanks again...


This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.