复杂表格的多个 TableLayoutPanels [英] Multiple TableLayoutPanels for complex table

查看:29
本文介绍了复杂表格的多个 TableLayoutPanels的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试构建与此类似的表格布局

I'm trying to build a table layout similar to this

 ---------------------------------------------------------------------
|   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            |
 ---------------------------------------------------------------------

它必须是动态创建的,所以我无法在表单设计器中创建它...

It has to be created dynamically, so I can't create it in the Form Designer...

第一种方法如下

// 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);

它似乎有效,因为我没有例外 - 但它看起来很糟糕.表格的宽度太短,文字列没有按照我上面描述的方式添加,我也有一种感觉,表格的高度太短了,因为有些文字在底部被截断了.

It seems to work, as I get no exceptions - but it looks horrible. The width of the table is too short, the text columns are not added in the way I described above and I also have the feeling, that the table is too short in height as some texts are cut off at the bottom.

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

Any better approaches to this? Or helpful tutorials regarding these matters?

推荐答案

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

I think you have the right structure. What I don't see is any Width/Height/Docking/Anchoring.

我想补充:

table.Dock = DockStyle.Fill;
dateTable.Dock = DockStyle.Top; 
textTable.Dock = DockStyle.Fill;

这篇关于复杂表格的多个 TableLayoutPanels的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆