ContainerControl + EmbedWithinPanel + Arrays

I tried to take the ContainerControl the code from the DownloadContainer example as an inspiration to put severals custom buttons inside a TabPanel using the EmbedWithinPanel but it’s not working.

My code:

Dim bt As New myButton
Dim i as integer = 0
For i = 1 to 3
Botoes.Append(bt)
Botoes(i-1).EmbedWithinPanel(Tabpanel1,0,40,100*i,140,40)
Next

I thought every time I did an EmbedWithin using a different array element it should show a new Button, but ti not what happening.

Try

For i As Integer = 1 To 3
  Botoes.append New myButton
  Botoes(i - 1).EmbedWithinPanel(Tabpanel1, 0, 40, 100 * i, 140, 40)
Next i

In your code you create 1 new button then append a reference to that button three times to your array. The keyword “New” needs to be within the loop to create multiple instances of myButton.

[quote=257353:@ALEXANDRE SANGALO]Dim bt As New myButton Dim i as integer = 0 For i = 1 to 3 Botoes.Append(bt) Botoes(i-1).EmbedWithinPanel(Tabpanel1,0,40,100*i,140,40) Next[/quote]
… should be:

Dim i as integer = 0 For i = 1 to 3 Dim bt As New myButton <- this line belongs into the loop, or only one button (i=3) will exist Botoes.Append(bt) Botoes(i-1).EmbedWithinPanel(Tabpanel1,0,40,100*i,140,40) Next

Isn’t that what I said?