469,900 Members | 1,437 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,900 developers. It's quick & easy.

ListBox size not growing to fill increased size of FlowLayoutPanel

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 ;

Mar 4 '07 #1
1 7038
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 ;

Mar 4 '07 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

12 posts views Thread by Brett L. Moore | last post: by
1 post views Thread by Annette Massie | last post: by
2 posts views Thread by DC Gringo | last post: by
7 posts views Thread by Dave | last post: by
1 post views Thread by Liam J | last post: by
3 posts views Thread by Ali Chambers | last post: by
1 post views Thread by Waqarahmed | last post: by
reply views Thread by Salome Sato | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.