I’m trying to add controls into my panel with vertical spacing?
This is my code for now:
Private Sub btnLoad_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLoad.Click
Dim pic As PictureBox = New PictureBox()
Dim lb As Label = New Label()
Dim cells As Integer = MoviesDataSet.movies.Count
ReDim mypb(cells)
ReDim mylb(cells)
Dim k As Integer = 0
For Each movie As DataRow In MoviesDataSet.movies
pic.ImageLocation = Application.StartupPath & "\" & movie("moviePhoto")
pic.Size = New System.Drawing.Size(x, y)
pic.SizeMode = PictureBoxSizeMode.StretchImage
pic.Margin = New System.Windows.Forms.Padding(0, 0, 0, 5)
mypb(k) = pic
lb.Text = movie("movieName")
lb.AutoSize = True
lb.Margin = New System.Windows.Forms.Padding(0, 0, 0, 10)
mylb(k) = lb
k += 1
Next
For i As Integer = 0 To MyPB.Count - 1 Step 1
Panel1.Controls.Add(MyPB(i))
Panel1.Controls.Add(MyLb(i))
Next
End Sub
My panel width is about 180 and height is about 170. I did that if the content is higher than the panel height, there are scroll bars. The code is adding all of the controls on the same spot so I can only see the last PHOTO.
How do I do that there will be a Photo, then a Label and then another photo and so on
Thanks!
If you want the images you place in your Control to be vertically aligned rather than all in the same position you need to calculate a new position for the control before placing it in the control.
I obviously can’t test your code but this kind of logic should suffice: