benst
benst

Reputation: 553

Controls are not added to tabpage VB.NET

I run the following code in the constructor of a window. The "label" gets added but none of the other controls are shown on screen. If I debug the newTab.Controls there are several controls in it. Why don't they show up on the screen and I only see the "label" control.

Thanks

Dim graphlist As ArrayList = New ArrayList
    For Each funct As TL_FUNCTION In functionlist
        If (funct.functionname = functi) Then
            If Not (graphlist.Contains(funct.picture)) Then
                graphlist.Add(funct.picture)
            End If
        End If
    Next
    For Each picture In graphlist
        Dim NewTab As New TabPage
        NewTab.Name = picture
        NewTab.Text = NewTab.Name
        Me.TabControl1.Controls.Add(NewTab)
        Me.TabControl1.SelectedIndex = Me.TabControl1.TabCount - 1
        For Each func As TL_FUNCTION In functionlist
            If (func.picture = picture) Then
                Dim label As Label = New Label
                label.Text = func.curve.ToString
                NewTab.Controls.Add(label) 'This label shows up
                Dim key As String
                Dim values() As String
                For Each key In func.values.Keys
                    values = func.values.GetValues(key)
                    For Each value As String In values
                        Dim label2 As New Label
                        label2.Text = key.ToString
                        Dim textb As TextBox = New TextBox
                        textb.Text = value
                        NewTab.Controls.Add(label2) 'this one is not shown on the tab
                        NewTab.Controls.Add(textb) 'this one is not shown on the tab
                    Next value
                Next key
            End If
        Next
    Next

Upvotes: 1

Views: 1109

Answers (1)

LarsTech
LarsTech

Reputation: 81675

You are placing the new labels and textboxes underneath the new label that you see in the TabPage because you never set their location, so it defaults to point (0, 0).

Try setting the location for the controls:

For Each value As String In values
  Dim label2 As New Label
  label2.Text = key.ToString
  label2.Location = New Point(10, NewTab.Controls.Count * 24)

  Dim textb As TextBox = New TextBox
  textb.Text = value
  textb.Location = New Point(label2.Right + 4, label2.Top)

  NewTab.Controls.Add(label2)
  NewTab.Controls.Add(textb)
Next value

Upvotes: 1

Related Questions