Hello everyone,
Visual Studio 2008 / .NET Framework 3.5:
Can someone tell me if this behaviour is normal:
Add a TableLayoutPanel on a WinForm, and set it up for 3 columns and 1 row. Make it dock the full client area of its parent window. Setup each column to have a 33% of total width. Also set its CellBorderStyle to Single to make the column widths visible.
Add a menu item on the form and hook it to this code:
private void menuItem1_Click(object sender, EventArgs e) { tableLayoutPanel1.ColumnStyles[0].SizeType = SizeType.Absolute; tableLayoutPanel1.ColumnStyles[0].Width = 200; }
So now when you click the menu, the 1st column changes its width from 33% to an absolute 200pt.
What do the other two columns do?
Visually, you can see that the other two columns are taking 50% of the remaining space each. Resize back and forth the form and you will see it's true.
So you should expect that ColumnStyles[1].SizeType == SizeType.Percent and ColumnStyles[1].Width == 50%. Same with column index 2.
However this isn't the case. Instead ColumnStyles[1].SizeType == SizeType.Percent and ColumnStyles[1].Width == 33% as it was at design time! The style collection has not been updated, despite the fact that the control draws itself correctly.
If you add a CellPaint handler to the tablelayout control you can verify it easier:
void tableLayoutPanel1_CellPaint(object sender, TableLayoutCellPaintEventArgs e) { string sSizeTypeX = tableLayoutPanel1.ColumnStyles[e.Column].SizeType.ToString(); string sSizeX = tableLayoutPanel1.ColumnStyles[e.Column].Width.ToString(); string sSizeTypeY = tableLayoutPanel1.RowStyles[e.Row].SizeType.ToString(); string sSizeY = tableLayoutPanel1.RowStyles[e.Row].Height.ToString(); e.Graphics.DrawString("("+sSizeTypeX+":"+sSizeX+","+sSizeTypeY+":"+sSizeY+")",tableLayoutPanel1.Font, Brushes.Black, e.CellBounds); }
Why should I manually update the style collection, since the control already knows what the column widths are?
To me this seems like a bug.
Anyone else can verify it / post an opinion?
Jason Orphanidis