我在我的TableLayoutPanel
中動態添加行,但我無法配置那裏的高度。如何在TableLayoutPanel中設置行的高度
該代碼可能看起來很長,但它是一個非常簡單的代碼。
有關代碼的解釋:
的代碼創建一個TableLayoutPanel
並設置其屬性。之後,根據數據庫中有多少部電影,該代碼將創建Pictureboxes
和Labels
。在創建Picturebox
和Label
後,該代碼將它們都放在Panel
中,然後代碼將Panel
插入到TableLayoutPanel
中。問題在於排的高度。
輸出:
這裏是我使用的代碼:
Dim movieN As Integer = MoviesDataSet.movies.Rows.Count
Dim tablePanel As New TableLayoutPanel
With tablePanel
.Size = New Point(Me.ClientRectangle.Width - 10, Me.ClientRectangle.Bottom - 55)
.ColumnCount = 4
.GrowStyle = TableLayoutPanelGrowStyle.AddRows
.AutoScroll = True
.Margin = New System.Windows.Forms.Padding(0)
.Location = New System.Drawing.Point(5, 50)
.CellBorderStyle = TableLayoutPanelCellBorderStyle.Inset
.ColumnStyles.Add(New ColumnStyle(SizeType.Percent, 25.0!))
.ColumnStyles.Add(New ColumnStyle(SizeType.Percent, 25.0!))
.ColumnStyles.Add(New ColumnStyle(SizeType.Percent, 25.0!))
.ColumnStyles.Add(New ColumnStyle(SizeType.Percent, 25.0!))
.Anchor = AnchorStyles.Bottom Or AnchorStyles.Left Or AnchorStyles.Right Or AnchorStyles.Top
End With
For Each MovieRow As DataRow In MoviesDataSet.Tables("movies").Rows
'define two new controls to be added
Dim myLabel As New Label
Dim myPicture As New PictureBox
Dim container As New Panel
'set the properties of the new controls
myLabel.Text = MovieRow("movieName")
myLabel.AutoSize = True
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
'here we add the controls to a layout panel to
'manage the positioning of the controls
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
'here we add a handler for the picture boxs click event
AddHandler myPicture.Click, AddressOf MyPictureClickEvent
Next
Me.Controls.Add(tablePanel)
End Sub
提前感謝!
是最後一行困擾着你? – AbZy
一切都在困擾着我。第一行沒有顯示標籤,這是因爲沒有足夠的高度給予該行,並且我不知道該怎麼做。 我想將所有**行的高度設置爲180 – kfirba