Vb.net 如果添加了控件,“流量布局”面板的自动高度
我使用的是流布局面板,流方向从左到右。在我的应用程序中,我必须在运行时在flowlayout面板上动态添加一些按钮,并且我不确定将在flowlayout面板上添加多少控件(按钮) 如果添加的控件(按钮)溢出flowlayout面板中的行,如何自动调整flow layout面板的高度 例如,如果面板上要添加8个控件,并且一行flowlayout面板中可以安装5个控件。对于剩下的3个控件,我需要增加面板的高度,以便这3个控件可以显示在下一行的oanel上 注意:在此过程中不会使用滚动条,控件的高度将精确到填充控件所需的行数 提前谢谢Vb.net 如果添加了控件,“流量布局”面板的自动高度,vb.net,winforms,Vb.net,Winforms,我使用的是流布局面板,流方向从左到右。在我的应用程序中,我必须在运行时在flowlayout面板上动态添加一些按钮,并且我不确定将在flowlayout面板上添加多少控件(按钮) 如果添加的控件(按钮)溢出flowlayout面板中的行,如何自动调整flow layout面板的高度 例如,如果面板上要添加8个控件,并且一行flowlayout面板中可以安装5个控件。对于剩下的3个控件,我需要增加面板的高度,以便这3个控件可以显示在下一行的oanel上 注意:在此过程中不会使用滚动条,控件的高度将
Private Sub CreateMainCategories()
'MsgBox(Me.TblItemMainCategoryDataGridView.Rows.Count)
Try
For Each row As DataGridViewRow In Me.TblItemMainCategoryDataGridView.Rows
Dim btnMainCatBtn As New Button
With btnMainCatBtn
.Name = ("btn" & row.Cells("MainCategoryName").Value).ToString.Replace(" ", "_")
.Text = row.Cells("MainCategoryName").Value
.Height = Me.FpnlMainCategoryBtnContainer.Height - 15
.Width = 150
'.Dock = DockStyle.Left
.Font = New Font("Calibri", 15)
.ForeColor = Color.White
.FlatStyle = FlatStyle.Popup
.BackColor = Color.Transparent
'.TextImageRelation = TextImageRelation.ImageAboveText
.TextAlign = ContentAlignment.MiddleCenter
'If System.IO.File.Exists(Application.StartupPath & "\Images\MainCategory\" & row.Cells("MainCategoryName").Value & ".JPEG") Then 'remove the image from directory if user remove the image
' .Image = Image.FromFile(Application.StartupPath & "\Images\MainCategory\" & row.Cells("MainCategoryName").Value & ".JPEG")
'Else
' .Image = Image.FromFile(Application.StartupPath & "\Resources\" & "imgEmpty.png")
'End If
End With
Me.FpnlMainCategoryBtnContainer.Controls.Add(btnMainCatBtn)
AddHandler btnMainCatBtn.Click, AddressOf MainCategoryButtonFeatures
'add panel
Dim SubCatBtnContPnl As New MyControls.MyFlowLayoutPanel
With SubCatBtnContPnl
.Name = ("pnl" & row.Cells("MainCategoryName").Value).ToString.Replace(" ", "_")
.BackColor = Color.Transparent
.TopColor = Color.Red
.BottomColor = Color.Black
.Dock = DockStyle.Fill
.AutoScroll = True
.WrapContents = False
.FlowDirection = FlowDirection.LeftToRight
End With
'MsgBox(SubCatBtnContPnl.Name)
Me.pnlMainCatPnlContainer.Controls.Add(SubCatBtnContPnl)
Next
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
向我们展示为我们重新创建问题的代码。我通过编辑问题添加了代码。请看一看。锚定FLP(左、上、右)并设置
AutoSize=True
。它将保持其宽度并调整其高度。顺便说一句,您显然有两个FlowLayoutPanel:一个接收按钮,另一个添加到未知的pnlMainCatPnlContainer
,该面板不承载任何内容,或者看起来没有功能。您可以忽略与上面类似的第二个面板。如果我得到上面的答案,它也将适用于下面的面板。您提供的解决方案有一个问题,当我们将anchor peooert和auto size属性设置为true时,它会删除其dock属性,同时我还希望面板停靠在其容器的顶部。停靠到顶部或停靠左、上、右是同一件事。结果没有改变。