复杂表格的多个 TableLayoutPanel

发布于 2024-09-15 01:45:42 字数 1317 浏览 6 评论 0原文

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

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

它似乎有效,因为我没有例外 -但看起来很可怕。表格的宽度太短,文本栏没有按照我上面描述的方式添加,我也有感觉,表格的高度太短,因为一些文本在底部被切断。

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

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 first approach was as followed

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

新人笑 2024-09-22 01:45:42

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

我想补充一点:

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

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

I would add:

table.Dock = DockStyle.Fill;
dateTable.Dock = DockStyle.Top; 
textTable.Dock = DockStyle.Fill;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文