【问题标题】:Controls are not added to tabpage VB.NET控件未添加到标签页 VB.NET
【发布时间】:2012-07-23 20:14:16
【问题描述】:

我在窗口的构造函数中运行以下代码。添加了“标签”,但屏幕上不显示任何其他控件。如果我调试 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

【问题讨论】:

  • 循环完成后,您是否尝试在标签控件上调用.Refresh()
  • 是的,试过 .Refresh(),没用。
  • ArrayList is obsolete.
  • arraylist 已过时是什么意思?
  • 使用 List(of T) 而不是 ArrayList。验证您的 func.values.GetValues(key) 数组中是否有内容。如果为空,则不会创建这些控件。

标签: vb.net winforms controls


【解决方案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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-11-07
    • 1970-01-01
    • 2012-08-27
    • 2011-03-28
    • 1970-01-01
    • 2010-11-25
    • 2018-01-03
    相关资源
    最近更新 更多