kfirba
Well-known member
- Joined
- Dec 29, 2012
- Messages
- 77
- Programming Experience
- 1-3
I'm trying to make a TableLayoutPanel with PictureBox + Label in each cell. I have got it all right but I just can't set the cells sizes to be the same! I'm trying to have 4 columns with endless number of rows, and I would like the cell to be in the Label width, unless the Label width is smaller than thePicture width.
For now, my code pretty much works, it just doesn't set the cell size because I have no idea how to do it.
Output image at the bottom of the post
Here is my code:
The output I get:

As you can see, the cell's width and height is just not right >.<
Thanks in advance!
For now, my code pretty much works, it just doesn't set the cell size because I have no idea how to do it.
Output image at the bottom of the post
Here is my code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim movieN As Integer = MoviesDataSet.movies.Rows.Count
Dim tablePanel As New TableLayoutPanel
With tablePanel
.Size = New Point(650, 450)
.ColumnCount = 4
.GrowStyle = TableLayoutPanelGrowStyle.AddRows
.AutoScroll = True
.Margin = New System.Windows.Forms.Padding(0)
.Location = New System.Drawing.Point(5, 50)
.CellBorderStyle = TableLayoutPanelCellBorderStyle.Inset
End With
For Each MovieRow As DataRow In MoviesDataSet.Tables("movies").Rows
Dim myLabel As New Label
Dim myPicture As New PictureBox
Dim container As New Panel
myLabel.Text = MovieRow("movieName")
myLabel.Location = New System.Drawing.Point(30, 110)
With myPicture
.Image = Image.FromFile(MovieRow("moviePhoto"))
.Tag = MovieRow("ID")
.Size = New System.Drawing.Size(100, 100)
.SizeMode = PictureBoxSizeMode.StretchImage
.Location = New System.Drawing.Point(2, 2)
.Cursor = Cursors.Hand
End With
With container
.Dock = DockStyle.Fill
.Margin = New System.Windows.Forms.Padding(0)
.Controls.Add(myPicture)
.Controls.Add(myLabel)
End With
With tablePanel.Controls
.Add(container)
End With
AddHandler myPicture.Click, AddressOf MyPictureClickEvent
Next
Me.Controls.Add(tablePanel)
End Sub
The output I get:

As you can see, the cell's width and height is just not right >.<
Thanks in advance!
