c#中可调整大小的表格布局面板
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/980489/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Resizable table layout panel in c#
提问by sudarsanyes
I find the table layout panel in c# (.net 2.0) to be very primitive. I wanted to allow my users to resize the columns in a table layout panel but there are no ready made options to do so. Is there a way atleast to find out whether the cursor is directly over any borders of a cell and if so, which cell is beneath it ?? May be having this information, we can atleast try resizing that row/column thru' code. Help me finding,
我发现 c# (.net 2.0) 中的表格布局面板非常原始。我想让我的用户在表格布局面板中调整列的大小,但没有现成的选项可以这样做。有没有办法至少找出光标是否直接位于单元格的任何边界上,如果是,则哪个单元格在其下方?可能有这些信息,我们至少可以尝试通过代码调整该行/列的大小。帮我找,
- whether the cursor is directly over any borders of a cell
- which cell is beneath it (applicable only if the first question has an answer)
- 光标是否直接位于单元格的任何边框上
- 哪个单元格在它下面(仅当第一个问题有答案时才适用)
Many Thanks,
非常感谢,
Sudarsan Srinivasan
苏达桑·斯里尼瓦桑
采纳答案by Fredrik M?rk
If your layout is not overly complex, maybe you can achieve what you want by using SplitContainercontrols? Unfortunately, each SplitContainer will have only two "cells", but you can embed a SplitContainer in another SplitContiner panel to get more resizable cells:
如果您的布局不是过于复杂,也许您可以通过使用SplitContainer控件来实现您想要的?不幸的是,每个 SplitContainer 只有两个“单元格”,但是您可以在另一个 SplitContiner 面板中嵌入一个 SplitContainer 以获得更多可调整大小的单元格:
┌──────────────────┐
│┌─────┬──────────┐│
││ │ ││
││ │ ││
│└─────┴──────────┘│
├──────────────────┤
│┌──────────┬─────┐│
││ │ ││
││ │ ││
│└──────────┴─────┘│
└──────────────────┘
OK, so ASCII art was never one of my stronger skills, but I think you get the point ;o)
好的,所以 ASCII 艺术从来都不是我的强项之一,但我想你明白了;o)
回答by tsemer
Building on top of @Fredrik M?rk's solution:
建立在@Fredrik M?rk 的解决方案之上:
After embedding another SplitContainer(s), the only drawback is that they don't automatically resize together, so you quickly lose the tabular view. A solution could be to set up a SplitterMoved
event handler for every applicable SplitContainer:
嵌入另一个 SplitContainer(s) 后,唯一的缺点是它们不会自动一起调整大小,因此您很快就会丢失表格视图。一个解决方案可能是SplitterMoved
为每个适用的 SplitContainer设置一个事件处理程序:
private void mySplitContainer_SplitterMoved(object sender, SplitterEventArgs e) {
mOtherySplitContainer.SplitterDistance = e.SplitX;
}
If your SplitContainer is horizontal use e.SplitX
, if it's vertical use e.SplitY
.
如果您的 SplitContainer 是水平使用e.SplitX
,如果它是垂直使用e.SplitY
。