1

我在窗口的构造函数中运行以下代码。添加了“标签”,但屏幕上不显示任何其他控件。如果我调试 newTab.Controls 里面有几个控件。为什么它们不显示在屏幕上,而我只看到“标签”控件。

谢谢

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
4

1 回答 1

1

您将新标签和文本框放置在您在 TabPage 中看到的新标签下方,因为您从未设置它们的位置,因此它默认为点 (0, 0)。

尝试设置控件的位置:

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
于 2012-07-25T14:26:30.020 回答