Adam

Adam

  • NA
  • 1
  • 0

SplitContainer Dynamic Sizing

Sep 6 2009 7:58 PM
Hi,

I have a windows form that has nested split containers that are dynamically created. This is done by a recursive method.
That works just fine. However, if I were to try to set the splitterDistance to 50, it would take up about 400 pixels on the screen and it would keep getting smaller with each... (Like matryoshka dolls)

Does anyone have an idea of whats going on and how i can fix it?

Method that makes the splitcontainers
private void buildContainer()
{
scCollection.Panel1.Controls.Clear();

if (columns.Count == 1)
{
scCollection.Panel1.Controls.Add(columns[0]);
}
else
{
scCollection.Panel1.Controls.Add(giveMeColumn(0, columns.Count));
}
}

private SplitContainer giveMeColumn(int current, int max)
{
SplitContainer newCol = new SplitContainer();


newCol.Panel1.Controls.Add(columns[current]);
if (current < max - 2)
{
newCol.Panel2.Controls.Add(giveMeColumn(current + 1, max));
}
else
{
newCol.Panel2.Controls.Add(columns[current + 1]);
}
newCol.SplitterDistance = 100;
//newCol.Dock = System.Windows.Forms.DockStyle.Fill;
newCol.Height = scCollection.Panel2.Height;
newCol.Width = 300;
newCol.BorderStyle = BorderStyle.FixedSingle;
newCol.Orientation = Orientation.Vertical;
newCol.Panel1.AutoScroll = true;
return newCol;
} "columns" is a array of panel objects