我正在尝试将控件添加到具有垂直间距的面板中?
这是我现在的代码:
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
我的面板宽度约为 180,高度约为 170。我这样做了,如果内容高于面板高度,则有滚动条。代码在同一个位置添加所有控件,所以我只能看到最后一张照片。
我该怎么做才会有一张照片,然后是一个标签,然后是另一张照片等等
谢谢!