作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在向我的 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
最佳答案
试试这个 :
For Each RS As RowStyle In tablePanel.RowStyles
RS.SizeType = SizeType.Absolute
RS.Height = 180
Next
关于vb.net - 如何在 TableLayoutPanel 中设置行高,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14711948/
我是一名优秀的程序员,十分优秀!