anchor ListBox to FlowLayoutPanel that Fills the Form

G

Guest

When I anchor a ListBox directly to the Form the ListBox widens as the Form
is widened. But when anchor the ListBox to a FlowLayoutPanel which in turn
is DockStyle.Fill in the Parent Form, the flow panel widens as the Form is
widened, but the ListBox gets left behind, never growing in size.

here is the code. Does anchor work as expected in a nested setting like this?

thanks,
-Steve

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;

// add some lines to the ListBox
for (int ix = 1; ix <= 30; ++ix)
{
box1.Items.Add(
"text line number " + ix.ToString() +
" " + box1.ToString( ));
}
return box1;
}

// property grid used to show the size and location of the clicked on control.
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();
}
 
J

Jared

nice bug you've found...I confirm NETFX20\VB.NET

Should report to connect.microsoft.com

I would always substitute a splitter with a panel any day, huge number of
bugs with splitters as well.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top