Panels added in inverse order.

Napivo1972

Well-known member
Joined
Aug 31, 2004
Messages
75
I am not sure if this goes here or in the VB specific thread as I am new here and rather new to vb.net. I migrated from VB6 to VB.net less than a week ago. And probably will have a lot of questions in the following week.

I have a panel (Panel1) on a form and I add panels to it with this code:

Code:
    Private AddButtons As ArrayList
    Private Panels As ArrayList
    Private NrTxtBoxes As ArrayList
    Private KlachtTxtBoxes As ArrayList

Private Sub addKlacht(ByVal nr As Long, ByVal Klacht As String)
        Dim newBtnAdd As System.Windows.Forms.Button = New System.Windows.Forms.Button
        Dim newTxtBox2 As System.Windows.Forms.TextBox = New System.Windows.Forms.TextBox
        Dim newTxtBox1 As System.Windows.Forms.TextBox = New System.Windows.Forms.TextBox
        Dim newPanel As System.Windows.Forms.Panel = New System.Windows.Forms.Panel

        
        newPanel
        
        newPanel.SuspendLayout()
        newPanel.BackColor = System.Drawing.Color.FromArgb(CType(255, Byte), CType(192, Byte), CType(128, Byte))
        newPanel.Controls.Add(newTxtBox1)
        newPanel.Controls.Add(newBtnAdd)
        newPanel.Controls.Add(newTxtBox2)
        newPanel.Dock = System.Windows.Forms.DockStyle.Top
        newPanel.Size = New System.Drawing.Size(332, 24)
        newPanel.Location = New System.Drawing.Point(0, newPanel.Height * (AddButtons.Count + 1))
        newPanel.Name = "newPanel"
        newPanel.TabIndex = 3
        Panel1.Controls.Add(newPanel)

        
        newBtnAdd
        
        newBtnAdd.BackColor = System.Drawing.SystemColors.ControlLightLight
        newBtnAdd.Location = New System.Drawing.Point(14, 2)
        newBtnAdd.Name = "AddButton"
        newBtnAdd.Size = New System.Drawing.Size(32, 20)
        newBtnAdd.TabIndex = 3
        If Klacht = csNew Then
            newBtnAdd.Text = csNew
        Else
            newBtnAdd.Text = csDel
        End If
        AddHandler newBtnAdd.Click, New EventHandler(AddressOf AddClick)
        AddButtons.Add(newBtnAdd)

        
        newTxtBox2
        
        newTxtBox2.Location = New System.Drawing.Point(62, 2)
        newTxtBox2.Name = "newTxtBox2"
        newTxtBox2.Size = New System.Drawing.Size(48, 20)
        newTxtBox2.TabIndex = 3
        newTxtBox2.Text = CStr(nr)
        newTxtBox2.Enabled = False
        NrTxtBoxes.Add(newTxtBox2)

        
        newTxtBox1
        
        newTxtBox1.Location = New System.Drawing.Point(126, 2)
        newTxtBox1.Name = "newTxtBox1"
        newTxtBox1.Size = New System.Drawing.Size(192, 20)
        newTxtBox1.TabIndex = 4
        newTxtBox1.Text = Klacht
        KlachtTxtBoxes.Add(newTxtBox1)
        newPanel.ResumeLayout(False)
    End Sub

What happens is that the new panels are added to the top of panel1 where I add them instead of to the bottom as I hoped. This forces me to fill the boxes in reverse order like the code below and that
 
Back
Top