Ich habe 2x2 automatisches Tabellenlayout und lange Beschriftungen in jeder Zelle. Dieses Layout befindet sich in einem anderen Tabellenlayout mit Zellen ohne Größe. Minimal-Projekt, das Problem zu reproduzieren:TableLayoutPanel hat falsche Zeilenhöhe
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);
}
}
}
ich folgendes Ergebnis:
Warum letzte Zeile in die falsche Höhe bekam? Gibt es eine Problemumgehung?