C# SplitContainer 中的固定面板高度
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1373596/
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
Fixed Panel Height in a SplitContainer
提问by Sakkle
I have a WinForm containing a bindingNavigator at the top and a splitContainer with two horisontal panels below it. The splitContainer fills the space not occupied by the bindingNavigator.
我有一个 WinForm,顶部包含一个 bindingNavigator,一个 splitContainer 下方有两个水平面板。splitContainer 填充了 bindingNavigator 未占用的空间。
I would like to set the bottom panel to a fixed height of, say 100 pixels, and have the top panel fill the rest of the space.
我想将底部面板设置为固定高度,例如 100 像素,并让顶部面板填充其余空间。
This is my current code:
这是我当前的代码:
kundeteamSplitContainer.SplitterDistance = kundeteamSplitContainer.Height - 100;
I would have thought that this would set the splitter distance dynamically to 100 pixels less than the total height at all times, making the bottom panel occupy the remaining 100 pixels. This does not work as intended though as the bottom panel keeps changing size when I re-size the form at run-time.
我原以为这会动态地将分割器距离设置为始终比总高度小 100 个像素,从而使底部面板占据剩余的 100 个像素。这不会按预期工作,因为当我在运行时重新调整表单大小时,底部面板会不断改变大小。
EDIT: I am sticking with the splitContainer if at all possible. Got a bunch of functionality related to hiding/showing the bottom panel already implemented and I don't want to do that work again.
编辑:如果可能的话,我会坚持使用 splitContainer。有一堆与隐藏/显示底部面板相关的功能已经实现,我不想再做这项工作。
采纳答案by Sakkle
As pointed out by Lee:
正如李所指出的:
Set the FixedPanelproperty to the panel you want to remain the same size.
将FixedPanel属性设置为要保持相同大小的面板。
This works like this:
这像这样工作:
teamSplitContainer.SplitterDistance = teamSplitContainer.Height - 100;
teamSplitContainer.FixedPanel = FixedPanel.Panel2;
回答by MartW
I'd use a TableLayoutControl for something like this rather than a Splitter.
我会使用 TableLayoutControl 来完成这样的事情,而不是 Splitter。
回答by Lee
Set the FixedPanelproperty to the panel you want to remain the same size.
将FixedPanel属性设置为要保持相同大小的面板。
回答by Julo
If you want only show and disable the panel (no automatic resize, no resize by the user) add to the code by Sakkle this line:
如果您只想显示和禁用面板(不自动调整大小,不由用户调整大小)通过 Sakkle 将以下行添加到代码中:
teamSplitContainer.IsSplitterFixed = true;