I don't seem to be able to adjust the row height of a single row TableLayoutPanel whose RowStyle is set to SizeType.Absolute with an explicit height value . See the demo code below. It doesn't seem to matter what value I put in the 2nd parameter (the height) of the RowStyle.Add method or whether I explicitly set the height via the property in the next statement.
I thought that perhaps the Labels I added to the cells were too big so I explicitly kept them small. That didn't help either.
Any ideas? Thanks. Steve
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; namespace TableLayoutPanel_Demo { public partial class Form1 : Form { private string[] labels = { "Label 1", "Label 2", "Label 3" }; private int[] columnSpan = { 2, 1, 2 }; public Form1() { InitializeComponent(); TableLayoutPanel tlpDemo = new TableLayoutPanel(); tlpDemo.GrowStyle = TableLayoutPanelGrowStyle.FixedSize;; tlpDemo.CellBorderStyle = TableLayoutPanelCellBorderStyle.Single; tlpDemo.Width = 300; // Add 5 columns tlpDemo.ColumnCount = 5; for (int i = 0; i < 5; i++) tlpDemo.ColumnStyles.Add(new ColumnStyle(SizeType.Absolute, tlpDemo.Width / tlpDemo.ColumnCount)); // Add 1 row tlpDemo.RowCount = 1; tlpDemo.RowStyles.Add(new RowStyle(SizeType.Absolute, 20)); //tlpDemo.RowStyles[0].Height = 10; // Add labels to the cells int nextCol = 0; for (int i = 0; i < labels.Length; i++) { Label lbl = new Label(); lbl.Height = 20; lbl.Text = labels[i]; lbl.Text = lbl.Text.TrimEnd(); lbl.Dock = DockStyle.Fill; lbl.Anchor = AnchorStyles.None; tlpDemo.Controls.Add(lbl, nextCol, 0); tlpDemo.SetColumnSpan(tlpDemo.Controls[i], columnSpan[i]); nextCol = nextCol + columnSpan[i]; } // Add the TableLayoutPanel to the Form this.Controls.Add(tlpDemo); } } }