6

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 ())
Yawar
  • 11,272
  • 4
  • 48
  • 80
  • Your TextBox needs to be MultiLine = true. Docking the TextBox to Fill won't work with the FlowLayoutPanel. Doesn't make sense. That FlowLayoutPanel should just be a panel in that case. – LarsTech Mar 05 '15 at 22:32
  • Did you try setting the `TextBox` height and width to the `FlowLayoutPanel`'s height and width? I'm not into F# but by based on the code snippet the `TextBox` height and width should set exclusively. – fujiFX Mar 05 '15 at 22:36
  • @LarsTech - OK! So making it a `Panel` instead of a `FlowLayoutPanel` and setting the `Dock` to `Fill` does solve the problem. Thanks! – Yawar Mar 05 '15 at 22:44
  • @fujiFX - thanks, it looks like `Panel` is the right control for this job. – Yawar Mar 05 '15 at 22:45

2 Answers2

4

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.

LarsTech
  • 80,625
  • 14
  • 153
  • 225
0

You can't really Dock inside a flow layout panel, it makes no sense.

A flow layout panel is used to contain a collection of controls that flow together (left to right, top to bottom), having one control fill it will negate the usefulness of the flow layout.

If you want to fill the columns with a text box, just use a Textbox with a Dock Fill and Multiline set to true

Haukman
  • 3,726
  • 2
  • 21
  • 33
DaveShaw
  • 52,123
  • 16
  • 112
  • 141
  • 1
    I did a little research just now. Turns out you can dock and anchor inside a `FlowLayoutPanel`, which will lay out the controls according to a specific logic: https://msdn.microsoft.com/en-us/library/ms171633%28v=vs.90%29.aspx – Yawar Mar 07 '15 at 19:59