在 C# Winforms 中将多个面板放置在 TableLayoutPanel 的单个单元格中

Placing multiple panels in a single cell of TableLayoutPanel in C# Winforms

我正在开发 C# Winforms 应用程序。我使用 TableLayoutPanel 将表单分成 table 个单元格。对于 table 布局的特定单元格,我想插入多个面板 - 一个接一个地插入,以便我可以使用 BringToFront() 在面板之间切换(仅针对该单元格)。

我在一个似乎有效的表格上尝试了同样的方法。在 table 布局的单元格中,我只能向其中添加一个面板。当我尝试在该单元格中添加其他面板时,这些面板会嵌入到第一个面板中。这使得面板之间的切换变得困难。

我还尝试将所有需要的面板插入一个空面板(放置在单元格中)。但是,我无法弄清楚如何在它的子面板之间切换。

注意:面板的切换是由table的其他单元格中的组合框选择触发的。

如果你想在面板之间切换,那总是会出错,因为底部面板将成为顶部面板的父级... @Hans Passant 在另一个主题中给出了解决方案并引用:

This can be worked around with View > (Other Windows) > Document Outline, drag the top panel back to the form. Still pretty painful, you typically have to edit the Location by hand and making any changes to the form in the designer later tends to slurp the panel back.

There are better ways to do this. Creating UserControls instead is highly recommended, they have their own design surface. Or use the RAD way and do this with a TabControl instead

全部学分:Credits