angelpro
Programmer
- Dec 20, 2011
- 6
Hello, I am new to VB.NET 2005 and what I am trying to do is to create an array of picture boxes at runtime and to display them to the form. Here is my code I have tried so far. If I run it step by step, when the first item of the array is showed on the form the counter increases at 1 then next item appears normally but the previous item disappears. Any help will be much appreciated. Thank you in advanced.
Private Sub loadqueens()
Dim pics(2) As PictureBox
Dim cnt As Integer = pics.Length
Dim i As Integer
Dim pb As New PictureBox
For i = 0 To cnt - 1
pics(i) = New PictureBox
pics(i) = pb
Next
i = 0
For i = i To cnt - 1
pics(i).Parent = Me
pics(i).Image = My.Resources.black_king_2d_icon
x = x + pics(i).Width
y = y
pics(i).Location = New System.Drawing.Point _
(x, y)
MsgBox(pics(i).Location.X)
pics(i).Visible = True
Me.Controls.Add(pics(i))
Next
End Sub
Private Sub loadqueens()
Dim pics(2) As PictureBox
Dim cnt As Integer = pics.Length
Dim i As Integer
Dim pb As New PictureBox
For i = 0 To cnt - 1
pics(i) = New PictureBox
pics(i) = pb
Next
i = 0
For i = i To cnt - 1
pics(i).Parent = Me
pics(i).Image = My.Resources.black_king_2d_icon
x = x + pics(i).Width
y = y
pics(i).Location = New System.Drawing.Point _
(x, y)
MsgBox(pics(i).Location.X)
pics(i).Visible = True
Me.Controls.Add(pics(i))
Next
End Sub