I am dynamically adding controls to a TableLayoutPanel.
It has 12 rows and 32 columns.
I divided the column widths so that the labels with labels were twice as wide as those with a TextBox, and the percentages are up to 100:
labels = 5% textBoxes = 2.5%
Since the line contains 24 text fields and 8 labels per line, this is 100% (40% of labels, 60% of text fields).
HOWEVER, the last column is a space, as you can see here:
http://warbler.posterous.com/the-32-column-is-wider-than-the-rest
And I need this space for shortcuts to show all my selves: they are really five characters wide ("00:00" ... "23:45") not four, as shown.
Based on empirical data (previous trial version and error), I could reduce the TLP width to skinny to the last column, but this does not solve the problem with my shortcuts - too skinny.
Here's how I stagger the controls in TLP (I set the percent width of the column at design time through the property page for the Columns collection)
private void AddPlatypusScheduleControlsToTableLayoutPanel() { try { this.SuspendLayout(); tableLayoutPanelPlatypusSchedule.ColumnCount = PLATYPUS_SCHEDULE_COL_COUNT; int ColNum = 0; int RowNum = 0; int LoopCounter = 1; var dt = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 0, 0, 0); while (LoopCounter <= QUARTER_HOUR_COUNT) { string lblName = string.Format("labelPS{0}", LoopCounter); var lbl = new Label { Name = lblName, Dock = DockStyle.Fill, Margin = new Padding(), Font = new Font("Microsoft Sans Serif", 7), TextAlign = ContentAlignment.MiddleCenter, Text = dt.ToString("HH:mm") }; tableLayoutPanelPlatypusSchedule.Controls.Add(lbl, ColNum, RowNum); string txtbxName1 = string.Format("textBoxLSA{0}", LoopCounter); var txtbxa = new TextBox { Name = txtbxName1, Dock = DockStyle.Fill, Margin = new Padding() }; string txtbxName2 = string.Format("textBoxLSB{0}", LoopCounter); var txtbxb = new TextBox { Name = txtbxName2, Dock = DockStyle.Fill, Margin = new Padding() }; string txtbxName3 = string.Format("textBoxLSC{0}", LoopCounter); var txtbxc = new TextBox { Name = txtbxName3, Dock = DockStyle.Fill, Margin = new Padding() }; tableLayoutPanelPlatypusSchedule.Controls.Add(txtbxa, ColNum + 1, RowNum); tableLayoutPanelPlatypusSchedule.Controls.Add(txtbxb, ColNum + 2, RowNum); tableLayoutPanelPlatypusSchedule.Controls.Add(txtbxc, ColNum + 3, RowNum); dt = dt.AddMinutes(15); RowNum++; LoopCounter++; if (RowNum == 12) { ColNum = ColNum + 4; RowNum = 0; } } } finally { this.ResumeLayout(); } }
UPDATE
I thought that maybe the problem was that the TLP width was not exactly divisible by 32 (this was 619); so I expanded it to 640, but the same problem remains.
UPDATE 2
To make it work, I had to use the absolute sizes for the columns, not the percentages *, and increase the width of the columns holding the labels to 35 (which leaves only 15 for columns containing Box text, with a TLP width of 640).
- WPF can be a bear at times (more like Kodiak than Winnie), but it probably fills the bill for situations where I worry that the absolute sizes in Dallas go to different resolutions / screen sizes, etc.