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

2

7

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 ())
Astronomical answered 5/3, 2015 at 22:30 Comment(4)
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.Freda
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.Lightly
@Freda - OK! So making it a Panel instead of a FlowLayoutPanel and setting the Dock to Fill does solve the problem. Thanks!Astronomical
@Lightly - thanks, it looks like Panel is the right control for this job.Astronomical
F
5

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.

Freda answered 5/3, 2015 at 22:47 Comment(0)
L
1

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

Lidless answered 5/3, 2015 at 22:47 Comment(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: msdn.microsoft.com/en-us/library/ms171633%28v=vs.90%29.aspxAstronomical

© 2022 - 2024 — McMap. All rights reserved.