1
我在每個單元格中都有自動調整的2x2表格佈局和長自動大小的標籤。 此佈局位於其他表格佈局中,沒有自動調整大小的單元格。 最少的項目來重現問題:TableLayoutPanel的行高不正確
using System;
using System.Windows.Forms;
namespace TestForms {
static class Program {
[STAThread]
static void Main() {
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new TestForm());
}
}
class TestForm : Form {
public TestForm() {
var childPanel = new TableLayoutPanel();
var label8 = new Label();
var label9 = new Label();
var label10 = new Label();
var label7 = new Label();
var rootPanel = new TableLayoutPanel();
childPanel.AutoSize = true;
childPanel.AutoSizeMode = AutoSizeMode.GrowAndShrink;
childPanel.BackColor = System.Drawing.Color.Silver;
childPanel.ColumnCount = 2;
childPanel.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 50F));
childPanel.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 50F));
childPanel.Controls.Add(label8, 1, 0);
childPanel.Controls.Add(label9, 0, 1);
childPanel.Controls.Add(label10, 1, 1);
childPanel.Controls.Add(label7, 0, 0);
childPanel.Dock = DockStyle.Top;
childPanel.RowCount = 2;
childPanel.RowStyles.Add(new RowStyle());
childPanel.RowStyles.Add(new RowStyle());
label8.AutoSize = true;
label8.Text = "2ggggggggggggggggg";
label9.AutoSize = true;
label9.Text = "label9";
label10.AutoSize = true;
label10.Text = "label10";
label7.AutoSize = true;
label7.Text = "label7";
rootPanel.ColumnCount = 1;
rootPanel.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 100F));
rootPanel.Controls.Add(childPanel, 0, 0);
rootPanel.Dock = DockStyle.Fill;
rootPanel.RowCount = 1;
rootPanel.RowStyles.Add(new RowStyle(SizeType.Percent, 100F));
ClientSize = new System.Drawing.Size(205, 197);
Controls.Add(rootPanel);
}
}
}
我得到以下結果:
爲什麼最後一行得到了錯誤的高度?有沒有解決方法?