winformsf#tablelayoutpanelflowlayoutpanel

How to force a WinForms control to fill up FlowLayoutPanel that's in a multi-column-spanning cell in a TableLayoutPanel?


I have a TextBox that's in a FlowLayoutPanel that's inside a cell of a TableLayoutPanel. The FlowLayoutPanel spans 5 columns of the TableLayoutPanel and fills up the entire width of the 5 columns. However, the TextBox doesn't fill up the entire width of the FlowLayoutPanel, as you can see here (the black border is the FlowLayoutPanel):

Test table layout panel

How can I get the TextBox to span the entire width of the FlowLayoutPanel?

Code to produce this example:

// fsi --exec Test.fsx
open System
open System.Windows.Forms

let frmMain () =
  let f = new Form(Text = "Test table layout panel")
  let tlp =
    new TableLayoutPanel
      ( ColumnCount = 5,
        RowCount = 1,
        AutoSize = true,
        Parent = f )
  let flp =
    new FlowLayoutPanel
      ( AutoSize = true,
        BorderStyle = BorderStyle.FixedSingle )
  let tb = new TextBox(Parent = flp)

  tlp.Controls.Add(flp, 0, 0)
  tlp.SetColumnSpan(flp, 5)
  flp.Dock <- DockStyle.Fill
  tb.Dock <- DockStyle.Fill

  f

[<STAThread>]
do
  Application.EnableVisualStyles()
  Application.Run(frmMain ())

Solution

  • Docking doesn't work inside a FlowLayoutPanel since it wants to layout the controls in a flowing order. Since you want to dock-fill the TextBox control, try using a simple Panel control instead.

    Also, set the Multiline property of the TextBox to true.