Splitcontainer flowlayoutpanel或autosized panel(VB.NET)

时间:2012-04-26 14:41:49

标签: vb.net autosize flowlayoutpanel splitcontainer

我正在与团队合作的应用程序中的表单将datagridview作为主要组件(它应占用大部分大小),但还有其他组件。有一个水平拆分容器来拆分它们,但我想知道如何让顶部面板调整其内容。不幸的是,splitcontainer中的面板没有AutoSize属性......

以下两张图片展示了我们的需求: image1 http://www.mediafire.com/conv/8d141b69c63b0d3ac8aebf9129bb77e25ee4a75086cfa6595c4510041fda1fa66g.jpg image2 http://www.mediafire.com/conv/56d959d2a9f99b71af16f7ab3eb5833874e8583f7b15bd1df16aafaa7313a7066g.jpg

如您所见,splitcontainer的顶部面板应根据其内容的大小进行调整。有没有办法实现这个目标?

1 个答案:

答案 0 :(得分:3)

我假设您的意思是基于图像的“水平”分割容器。

您可以尝试使用顶部面板的ControlAdded事件手动实现此目的:

Public Class Form1

  Public Sub New()
    InitializeComponent()
  End Sub

  Private Sub Form1_Shown(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Shown
    SplitContainer1.SplitterDistance = SmallPanel.Height
  End Sub

  Private Sub SplitContainer1_Panel1_ControlAdded(ByVal sender As Object, ByVal e As ControlEventArgs) Handles SplitContainer1.Panel1.ControlAdded
    SplitContainer1.SplitterDistance += e.Control.Height
  End Sub

  Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    Dim addPanel As New Panel
    addPanel.BorderStyle = BorderStyle.FixedSingle
    addPanel.Size = New Size(SplitContainer1.Panel1.ClientSize.Width, 100)
    addPanel.Location = New Point(0, SplitContainer1.SplitterDistance)
    addPanel.Anchor = AnchorStyles.Left Or AnchorStyles.Top Or AnchorStyles.Right
    SplitContainer1.Panel1.Controls.Add(addPanel)
  End Sub

End Class

SmallPanel是我放置在SplitContainer的Panel1中的面板,并在其中添加了一个按钮以添加更多面板。