I have a forms application that loads forms into panel controls. Each form has the borders turned off via the FormBorderStyle property and are maximised on load, so they appear to "fill" the panel. E.g in form1.vb I might have something like:

Inherits System.Windows.Forms.Form
Public Class form1
Enum eLayout
Main
Left
Right
End Enum

Public Sub ShowForm(ByVal f As Object, ByVal panel As eLayout)
f.TopLevel = False
Select Case panel
Case eLayout.Main
Me.pnlMain.Controls.Add(f) ' pnlMain being a panel on Form1
f.Dock = DockStyle.Fill ' Fill form space
Case eLayout.Left
' etc
End Select
f.Show()
End Sub

Private frm2 as New Form2

Private Sub frmMain_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
ShowForm(frm2, eLayout.Main)
End Sub
End Class


The Me.pnlMain.Controls.Add(f) will add the control to pnlMain.
Problem 1): If I resize the form, frm2 will not resize, even though its DockStyle is set to "fill". Interestingly, if I doa "for each" in the panel and remove all controls before adding frm2, it will resize with the window resize.

If pnlMain already has controls in it (that I want to keep), frm2 might not be positioned in the right spot - e.g. after any controls in the panel. I've had to add routines to check the size of panels and expand or shrink them down depending on the size of the controls contained within them.

Is there a good library for positioning dynamically added controls (including subforms) inside container objects? The sort of things I need to do are:

- Shrinking controls to the minimum size based on the data presented within them. For instance, shortening or lengthening the height of a TextBox to the length of all lines so they are all visible without a scrollbar, OR shrinking a panel to the width/height of all its contents
- Flow layout stuff - adding buttons "next to" each (right, left, below, above) other dynamically without having to keep track of X/Y/W/H of items
- Stretching the width of buttons, labels, etc so that all the text is shown and isn't clipped.
- Loading and manipulating controls on subforms, or manipulating controls on parent forms FROM subforms (e.g. adding or removing controls and having the document flow automatically update).