InitLayout won't give you what you want because it gets executed too early.
With the TableLayoutPanel, you have to do it in OnLayout, as Bill showed.
You don't have to put the Width and Height in there. You can do that dynamically, like this:
public partial class CustomTableLayoutPanel : TableLayoutPanel
{
protected override void OnLayout(LayoutEventArgs levent)
{
this.ColumnCount = 5;
this.RowCount = 5;
Single colWidth = 100 / this.ColumnCount;
Single rowHeight = 100 / this.RowCount;
foreach (ColumnStyle colStyle in this.ColumnStyles)
{
colStyle.SizeType = SizeType.Percent;
colStyle.Width = colWidth;
}
foreach (RowStyle rowStyle in this.RowStyles)
{
rowStyle.SizeType = SizeType.Percent;
rowStyle.Height = rowHeight;
}
base.OnLayout(levent);
}
}
The TLP wasn't really designed to be customized like you want. There is a problem with doing it this way. You cannot change the number of rows and columns in the grid!
You can modify the code above to give you the number of rows and columns and even set the row and column styles. But, They will be forever locked to those values.
In order to get various other size grids, you'd have to make a custom TLP for every size you want!