more code to illustrate the problem:
public Form1()
{
InitializeComponent();
// the ListBox does not widen as I widen the form.
FlowLayoutPanel flow = AddFlowLayoutToForm(this);
AddListBoxToControl(flow);
return ;
// if this code is run, the ListBox does widen as the form is widened.
AddListBoxToControl( this ) ;
}
public FlowLayoutPanel AddFlowLayoutToForm(Form InForm)
{
FlowLayoutPanel flow = new FlowLayoutPanel();
flow.Parent = InForm;
flow.Dock = DockStyle.Fill;
flow.Click += Click_ObjectPropertyGrid;
return flow;
}
public ListBox AddListBoxToControl(Control InControl)
{
ListBox box1 = new ListBox();
box1.Parent = InControl;
box1.Size = InControl.ClientSize;
box1.Location = new Point(0, 0);
box1.Anchor = AnchorStyles.Left | AnchorStyles.Right;
box1.Click += Click_ObjectPropertyGrid;
box1.Font = new Font("Lucida Console", box1.Font.Size + 3);
box1.ForeColor = Color.Brown;
for (int ix = 1; ix <= 30; ++ix)
{
box1.Items.Add(
"text line number " + ix.ToString() +
" " + box1.ToString( ));
}
return box1;
}
void Click_ObjectPropertyGrid(object objSrc, EventArgs args)
{
Control ctrl = (Control)objSrc;
Form form = new Form();
form.Text = ctrl.ToString();
form.Owner = this;
PropertyGrid prop = new PropertyGrid();
prop.SelectedObject = objSrc;
prop.Parent = form;
prop.Dock = DockStyle.Fill;
form.Show();
}
On Mar 3, 11:54 pm, "Steve Richter" <StephenRich...@gmail.comwrote:
I have a form.
In the Form is a MenuStrip and a FlowLayoutPanel.
In the FlowLayoutPanel is a ListBox.
The FlowLayoutPanel is set to DockStyle.Fill.
The ListBox is set to AnchorStyles.Left | AnchorStyles.Right
I am able to verify that the FlowLayoutPanel grows in size as the form
is widened. But the ListBox stays the same size. It does not anchor
to the left and right.
When I place the ListBox directly in the Form and drop the
FlowLayoutPanel and the MenuStrip the ListBox does widen as the form
is widened.
How do I get the ListBox in the FlowLayoutPanel to increase in size as
the FlowLayoutPanel is widened?
thanks,
mFlow = new FlowLayoutPanel();
mFlow.Parent = this;
mFlow.AutoSize = true;
mFlow.Dock = DockStyle.Fill;
mMenu = new MenuStrip();
mMenu.Parent = this;
ToolStripMenuItem item =
(ToolStripMenuItem)mMenu.Items.Add("&Commands", null,
CommandsOnClick);
item = (ToolStripMenuItem)mMenu.Items.Add("FlowSize", null,
FlowSizeOnClick);
mListBox1 = new ListBox();
mListBox1.Parent = mFlow;
mListBox1.Size = mFlow.ClientSize;
mListBox1.Location = new Point(0, 0);
mListBox1.Anchor = AnchorStyles.Right | AnchorStyles.Left ;