2012-07-25 68 views
1

我在窗口的構造函數中運行以下代碼。 「標籤」被添加,但沒有其他控件顯示在屏幕上。如果我調試newTab.Controls,那裏有幾個控件。爲什麼他們不出現在屏幕上,我只看到「標籤」控件。控件不會添加到tabpage VB.NET

感謝

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 
+0

你有沒有打過電話'.REFRESH()'你的標籤控制,一旦循環完成? – 2012-07-25 11:51:59

+0

是的嘗試.Refresh(),沒有工作。 – benst 2012-07-25 11:55:03

+0

'ArrayList' [is obsolete](http://stackoverflow.com/a/5063253/284240)。 – 2012-07-25 11:55:30

回答

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 
+0

謝謝,不敢相信我沒有想到這一點。我現在工作。 – benst 2012-07-26 07:20:10

相關問題