vb.net WinForms SplitContainer 及其间距和调整大小

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15898784/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-17 13:11:23  来源:igfitidea点击:

WinForms SplitContainer and its spacing and resizing

vb.netwinformsvisual-studiosplitcontainer

提问by IAbstract

I seem to have a lot of trouble getting a SplitContainer adjusted the way I like it. I have the following form called frmMain:

我似乎很难按照我喜欢的方式调整 SplitContainer。我有一个名为 frmMain 的表单:

frmMain Screenshot

frm主屏幕截图

In the form Load code I have to following code:

在表单加载代码中,我必须遵循以下代码:

With MainContainer
    .IsSplitterFixed = True
    .Dock = DockStyle.Fill
    .SplitterDistance = 200
    .FixedPanel = FixedPanel.Panel1
    .Panel1.BackgroundImage = Resources.My.Resources.ResourceFile._001
    .Panel2.BackColor = Color.White
    .Panel2.AutoScroll = True
End With

When I run the code I get the following:

当我运行代码时,我得到以下信息:

frmMain (Compiled)

frmMain(已编译)

I want to remove the gray splitter since there is no use to it. Is this a common beauty bug and is it possible to remove it?

我想删除灰色分离器,因为它没有用。这是一种常见的美容错误吗,是否可以将其删除?

My second problem with the SplitContainer is if I resize my window, the backgroundImage in Panel1 and the white color in Panel2 don't adjust with the window. I searched high and low to the Resize code but I can't find it. The Panel2 has User Controls, eg. Dashboard and are loaded this way: MainContainer.Panel2.Controls.Add(Dashboard).

我对 SplitContainer 的第二个问题是,如果我调整窗口大小,Panel1 中的 backgroundImage 和 Panel2 中的白色不会随窗口一起调整。我搜索了调整大小代码的高低,但我找不到它。Panel2 具有用户控件,例如。仪表板并以这种方式加载:MainContainer.Panel2.Controls.Add(Dashboard)

Is it also possible that Panel2 automatically adjusts to the weidht of the window so thay you only have a hortizontal scrollbar?

Panel2 是否也有可能自动调整到窗口的重量,所以你只有一个水平滚动条?

Thank you for reading my question and hopefully you can help me solve my problems with the SplitContainer. Have a nice day.

感谢您阅读我的问题,希望您能帮助我解决 SplitContainer 的问题。祝你今天过得愉快。

回答by erdomke

I want to remove the gray splitter since there is no use to it. Is this a common beauty bug and is it possible to remove it?

我想删除灰色分离器,因为它没有用。这是一种常见的美容错误吗,是否可以将其删除?

If you don't want the user to see or move the splitter, why use a split container? As an alternative, consider using a TableLayoutPanel configured with 1 row and 2 columns. The first column would be an absolute 200 px wide while the second column would be set to 100% wide. In each of the two cells, you could place a panel which is docked and set to have a margin of 0,0,0,0.

如果您不希望用户看到或移动拆分器,为什么要使用拆分容器?作为替代方案,请考虑使用配置为 1 行和 2 列的 TableLayoutPanel。第一列的绝对宽度为 200 像素,而第二列将设置为 100% 宽度。在两个单元格中的每一个单元格中,您都可以放置一个面板,该面板停靠并设置为边距为 0,0,0,0。

My second problem with the SplitContainer is if I resize my window, the backgroundImage in Panel1 and the white color in Panel2 don't adjust with the window. ... Is it also possible that Panel2 automatically adjusts to the weidht of the window so thay you only have a hortizontal scrollbar?

我对 SplitContainer 的第二个问题是,如果我调整窗口大小,Panel1 中的 backgroundImage 和 Panel2 中的白色不会随窗口一起调整。... Panel2 是否也有可能自动调整到窗口的重量,所以你只有一个水平滚动条?

While I did not mock up your current solution, I was not able to replicate these problems with a quick mock up of the solution I proposed above. With regards to auto-scrolling, the only reason that scroll bars should appear would be if a control is off the edge of the screen or the available screen space is less than the minimum size of the panel.

虽然我没有模拟您当前的解决方案,但我无法通过快速模拟我上面提出的解决方案来复制这些问题。关于自动滚动,出现滚动条的唯一原因是控件超出屏幕边缘或可用屏幕空间小于面板的最小尺寸。

回答by IAbstract

You have 2 options:

您有 2 个选择:

  • Use TableLayoutPanel(as @erdomke suggests)
  • Use 2 Panelcontrols
  • 使用TableLayoutPanel(如@erdomke 建议的那样)
  • 使用 2 个Panel控件

For 2 panel controls, dock panel1to Left, and dock panel2to Fill. To fill panel2 with a UserControl that resizes, set it's Dock property also to Fill.

对于 2 个面板控件,停靠panel1Left和停靠panel2Fill。要使用可调整大小的 UserControl 填充 panel2,请将其 Dock 属性也设置为 Fill。