Here is a generic algorithm I wrote to add multiple items to a panel with
splitters between them. This should handle between 1..N controls.
Control main = null;
Control p = null;
Spliter sp = null;
ArrayList list = new ArrayList();
....
add controls to list that you want to have splitters between
....
// loop through the list of controls that we want to add to the panel
// with a horizontal splitter between each one.
// We will loop through the list backwards to get the items to start
// at the top with the first item in the list
for (int nIndex = list.Count - 1; nIndex >= 0; nIndex--)
{
// if we already have a panel, then add the current panel to a new panel as
a fill and add a splitter
if (main != null)
{
// store a reference to the current control
p = main;
// create a new panel control that will hold the old control and the
current list item
main = new Panel();
main.Dock = DockStyle.Fill;
// add the previous control to the panel
main.Controls.Add(p);
// create a new splitter and add it to the new panel we just created
sp = new Splitter();
sp.Dock = DockStyle.Top;
main.Controls.Add(sp);
// set the previous control to dock at the top and then add it to the new
panel
// we just created
((Control)list[nIndex]).Dock = DockStyle.Top;
main.Controls.Add((Control)list[nIndex]);
}
else
{
// set the main control to the current list item control that
// we are iterating through
((Control)list[nIndex]).Dock = DockStyle.Fill;
main = (Control)list[nIndex];
}
}
// set the dock and height of final control and add it to the
// client panel we want to display it in
main.Dock = DockStyle.Top;
main.Height = (int)(panel1.Height * .5 * list.Count);
panel1.Controls.Add(main);
Although this simply adds 1..N controls with horizontal splitters between
them, it can be customized to do vertical or mixed for any number of controls.
Ashton Hobbs
ApexSQL Edit
http://www.apexsql.com