C# 如何隐藏 SplitContainer 上的面板?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/645518/
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
How can I hide a panel that is on a SplitContainer?
提问by CrashCodes
I want to hide panel2 on a split container and have panel1 utilize the space. I was hoping setting Panel2Collapsed would do the trick, but no luck. Ideas?
我想在拆分容器上隐藏 panel2 并让 panel1 利用该空间。我希望设置 Panel2Collapsed 可以解决问题,但没有运气。想法?
采纳答案by Nikos Steiakakis
This worked for me on a similar situation:
这在类似的情况下对我有用:
splitContainer1.Panel2Collapsed = true;
splitContainer1.Panel2.Hide();
I wanted the second panel to not be visible at all in some cases, so I implemented it this way.
在某些情况下,我希望第二个面板根本不可见,因此我以这种方式实现了它。
回答by Andrew Peters
Try setting panel2.Visible = false.
尝试设置 panel2.Visible = false。
回答by Daniel LeCheminant
Setting Panel2Collapsed
property to true
in the form designer and programatically both work as you want them to (i.e. Panel1 then occupies all of the space)... so there must be something else going on.
将Panel2Collapsed
属性设置为true
在表单设计器中并以编程方式都可以按照您的意愿工作(即 Panel1 然后占据所有空间)...所以必须有其他事情发生。
回答by user2581948
this.splitContainerControl1.Panel2.Hide();
this.splitContainerControl1.Panel2.Height = 0;
this.splitContainerControl1.IsSplitterFixed = true;
This worked for me.
这对我有用。
回答by Thomas Papageorgiou
splitContainer1.PanelVisibility = SplitPanelVisibility.Panel1
splitContainer1.PanelVisibility = SplitPanelVisibility.Panel1
回答by Donald
With Visual Studio 2017 it is a little more trick. This is what I got to work for me. MyControl is inside panel1.
在 Visual Studio 2017 中,这有点技巧。这就是我必须为我工作的原因。MyControl 位于 panel1 内。
'vb.net:
MySplitContainer.Panel2Collapsed = True
MySplitContainer.Panel2.Hide()
MySplitContainer.SplitterDistance = MySplitContainer.Height
MySplitContainer.Panel1.Anchor = AnchorStyles.Bottom
MyControl.Height = MySplitContainer.Height
'for C# just add a semi-colon onto the end of each line and it should work.