复杂表的多个TableLayoutPanel

时间:2010-08-20 07:56:38

标签: c# winforms user-interface tablelayoutpanel

我正在尝试构建类似于此

的表格布局
 ---------------------------------------------------------------------
|   01.01.2010 01:00   |   01.01.2010 01:00   |   01.01.2010 01:00    |
 ---------------------------------------------------------------------
|   Some text       |  More            | And         | Final text     |
|   (Multilined)    |  multilined      | more text   | Multiple lines,|
|                   |  text            |             | too            |
 ---------------------------------------------------------------------

必须动态创建,因此我无法在表单设计器中创建它...

第一种方法如下:

// The "outer" table - two rows (the dates and the texts)
TableLayoutPanel table = new TableLayoutPanel();
table.ColumnCount = 1;
table.RowCount = 2;

// Date table - three columns
TableLayoutPanel dateTable = new TableLayoutPanel();
dateTable.ColumnCount = 3;
dateTable.RowCount = 1;

// Text table - four columns
TableLayoutPanel textTable = new TableLayoutPanel();
textTable.ColumnCount = 4;
textTable.RowCount = 1;

// Add it all up and save it to the panel in the winform
table.Controls.Add(dateTable);
table.Controls.Add(textTable);
SomeUIPanel.Controls.Add(table);

它似乎有效,因为我没有例外 - 但它看起来很可怕。桌子的宽度太短,文字栏没有按照我上面描述的方式添加,我也有这样的感觉,桌子的高度太短,因为有些文字被剪掉了。

有更好的方法吗?或者有关这些问题的有用教程?

1 个答案:

答案 0 :(得分:2)

我认为你有正确的结构。我没看到的是任何宽度/高度/对接/锚定。

我想补充一下:

table.Dock = DockStyle.Fill;
dateTable.Dock = DockStyle.Top; 
textTable.Dock = DockStyle.Fill;
相关问题