简体   繁体   English

Splitcontainer flowlayoutpanel或autosized panel(VB.NET)

[英]Splitcontainer flowlayoutpanel or autosized panel (VB.NET)

Forms in an application I'm working on with a team have a datagridview as main component (it should take up most of the size), but there are other components. 我正在与团队合作的应用程序中的表单具有datagridview作为主要组件(它应占用大部分大小),但还有其他组件。 there is a horizontal splitcontainer to split them, but I was wondering how to make the top panel resize to its contents. 有一个水平拆分容器来拆分它们,但我想知道如何让顶部面板调整其内容。 Unfortunately, the panels in a splitcontainer don't have an AutoSize property... 不幸的是,splitcontainer中的面板没有AutoSize属性......

Here are two images to show what we need: 以下两张图片展示了我们的需求: 此搜索
(source: mediafire.com ) (来源: mediafire.com

图像2
(source: mediafire.com ) (来源: mediafire.com

As you can see, the top panel of the splitcontainer should adjust to the size of its contents. 如您所见,splitcontainer的顶部面板应根据其内容的大小进行调整。 Is there any way to achieve this? 有没有办法实现这个目标?

I'm assuming you meant "horizontal" split container based on your image. 我假设您的意思是“水平”拆分容器,基于您的图像。

You can try achieving this manually by using the ControlAdded event of the top panel: 您可以尝试使用顶部面板的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 is a panel I placed in Panel1 of the SplitContainer and added a button in their to add more panels. SmallPanel是我放置在SplitContainer的Panel1中的面板,并在其中添加了一个按钮以添加更多面板。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM