I'm new to C# and may be missing something obvious. I've found only one related question here, and it was not exactly a match nor very authoritative.
What I want is to make it so that I can dock a control inside a FlowLayout (set left-to-right) so that it will fill the whole vertical space, and when the user resizes the Form, the controls resize to continue filling the whole vertical space. Can this be done, and if so, how?
What I've found:
I've created a Form. I've coloured it red. I've added a FlowLayout which I've coloured green and set the Dock to fill the Form. This seems to work (the Form is now all green, no red visible).
I then add a couple of controls to the FlowLayout (which is running left-to-right). If I dock them top, it works as expected. If I dock them bottom, it is the same as top; suggesting the vertical space is not really the whole green area. Docking left, right or fill the components won't appear at all unless I give them a minimum size > 0.
I have some code which shows what I mean; I have added some size to one of the controls and it can be seen that this seems to resize to the minimum vertical size allowed. The output screenshot is included.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.OleDb;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace ViewData
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
CustomComponentLayout();
}
private void CustomComponentLayout()
{
FlowLayoutPanel pnlHorFlow;
pnlHorFlow = new FlowLayoutPanel();
this.Controls.Add(pnlHorFlow);
pnlHorFlow.Dock = DockStyle.Fill;
pnlHorFlow.BackColor = Color.Green;
// Add a panel with some size
Panel testPanel = new Panel();
testPanel.Dock = DockStyle.Fill;
testPanel.BackColor = Color.BlanchedAlmond;
// Need these to get anything
testPanel.MinimumSize = new Size(200, 400);
pnlHorFlow.Controls.Add(testPanel);
Button testButton;
testButton = new Button();
testButton.Text = "Test";
testButton.Anchor = AnchorStyles.Top & AnchorStyles.Bottom;
testButton.Dock = DockStyle.Left;
pnlHorFlow.Controls.Add(testButton);
}
private void Form1_Load(object sender, EventArgs e)
{
}
}
}
EDIT
Ok, so the answer below doesn't answer the question, but I've accepted it because I am now convinced that the answer is that FlowLayoutPanel just can't do this. The answer (at least the edit) is about as close as I'll get. Playing with TableLayoutPanel seems to be the only way to get what I need.
For those in this boat, I also found this helpful.
I've found a lot of people making the same wrong assumptions about FlowLayoutPanel as me. I think in my case it ius because I have a Java background, and FlowLayouts work differently in Java.