动态加入控件时,为什么后添加的控件Index值小而先添加的值更大呢?
dim xpage as new TabPage()
dim xcon as myControl
xcon=new Mycontrol
xPage.Controls.Add(xCon)
用以上方法在页面里添加了控件后发现 后加的控件Index值最小,通常我们往一个集合里加东西都是先加入的index小后加的值大。为什么这里会是这样呢?会不会有什么巧门?
[解决办法]
用以下代码测试了下,没发现后加的Index值小啊
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim tab As New TabPage With {.Text = "test"} For i As Integer = 0 To 5 Dim btn As New Button With {.Text = "Button" + i.ToString} btn.Top = btn.Height * i + 10 tab.Controls.Add(btn) Next For Each Button As Button In tab.Controls MsgBox(Button.Text + " " + tab.Controls.IndexOf(Button).ToString) Next End Sub
[解决办法]
学习!
[解决办法]
学习.