views:

111

answers:

2

I have an issue with TableLayoutPanel, which fills an userControl (DockStyle.Fill). I face a trouble, when this control is being resized, I need all cells to change their size, but only last row and last column changes size (so whole tableLayoutPanel fills the control). I change this controler size using Bounds property.

let's say I wrote following code:

// creating tableLayoutPanel:

private void createTableLayoutPanel(int count)
{
    tableLayoutPanel = new TableLayoutPanel();
    tableLayoutPanel.MouseClick += new MouseEventHandler(this.observe_MouseClick);
    tableLayoutPanel.AutoSize = true;
    tableLayoutPanel.ColumnCount = 3;
    tableLayoutPanel.RowCount = count;
    tableLayoutPanel.Dock = DockStyle.Fill;
    tableLayoutPanel.AutoSize = true;
    this.Controls.Add(tableLayoutPanel);
}

// resizing:

private void OnMouseWheel(MouseEventArgs e)
{
    this.Bounds = new Rectangle(this.Location.X, this.Location.Y, (int)(this.Width*newScale),(int)(this.Height*newScale));
}

Thanks for any help.

+1  A: 

For each row, add an item to the TableLayoutPanel's RowStyles collection with SizeType = SizeType.Percent and Height = 100 / tableLayoutPanel.RowCount. Do the same with the ColumnStyles collection.

Tim Robinson
A: 

Thanks alot! I didn't know that I have to add RowStyles and ColumnStyles (tableLayoutPanel.RowStyles.Add) manually, so it didn't works before.

Thank you for help.