vb.net 面板成型高度
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13669177/
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
Form height of panel
提问by user1794844
I am having questions about a program that I'm developing. Sorry if my post is not clearly legible, as a beginner programming perfectionist I try to explain everything clearly as possible.
我对我正在开发的程序有疑问。抱歉,如果我的帖子不是很清晰,作为初学者编程完美主义者,我尝试尽可能清楚地解释所有内容。
I have a Windows Form called frmMain.vb with two separate panels, one is called sidebarPanel and the other one is called mainPanel:
我有一个名为 frmMain.vb 的 Windows 窗体,它有两个单独的面板,一个称为 sidebarPanel,另一个称为 mainPanel:


At runtime, this is how the form looks like: I reduced the screen to let it fit in this topic, the actual size is 900, 600 through this code at frmMain_Load:
在运行时,表单是这样的:我缩小了屏幕以适应这个主题,实际大小是 900,通过 frmMain_Load 中的这段代码,600:
Me.Size = New Size(900, 600)


Now I have created the following piece of code:
现在我已经创建了以下代码:
With sidebarPanel
.Top = 0
.Left = 0
.Width = 200
.Height = 300
End With
With mainPanel
.Top = 0
.Left = 200
.Width = 200
.Height = 300
End With
In case you're wondering how the sidebar is blue, that piece comes from a dll, that piece of the code I've left out to keep this question easy. If you look closely at the source code you can see that the sidebar has a width of 200 and the mainpanel start 200 width from the left.
如果您想知道侧边栏是蓝色的,那部分来自 dll,为了让这个问题更容易,我省略了那部分代码。如果仔细查看源代码,您会发现侧边栏的宽度为 200,而主面板从左侧开始宽度为 200。
With that out of the way. I want to know the answer, I've searched Stackoverflow, Google and some VB.NET forums about these questions but I seem to be a loner.
有了这个。我想知道答案,我已经搜索过 Stackoverflow、Google 和一些 VB.NET 论坛关于这些问题,但我似乎是一个孤独的人。
How can I make the sidebar a full 100% height to the form so if I resize, the sidebar will change height too. That same question goes for the mainpanel.
我怎样才能使侧边栏的高度达到表单的完整 100%,所以如果我调整大小,侧边栏也会改变高度。同样的问题也适用于主板。
Thank you for reading and thank you for the hospitality and the answer.
感谢您的阅读,感谢您的热情款待和答复。
回答by Steven Doggart
You can manually do so in the form's Resizeevent, by setting the Heightproperty of the panels to Me.ClientSize.Height, however, it's easier to just do it all at design time.
您可以在表单的Resize事件中手动执行此操作,方法是将Height面板的属性设置为Me.ClientSize.Height,但是,在设计时完成所有操作会更容易。
To do so, in the form designer, first position and resize the panels so that they are where you want them to be for the current form size, then set the Dockproperty appropriately on both. You want the side panel's Dockproperty to be set to Top, Left, and Bottom. You probably want the main panel's Dockproperty set to Top, Bottom, Left, and Right (all four sides). When the dock property is set properly, the controls will automatically resize themselves as the form is resized.
为此,在表单设计器中,首先定位面板并调整其大小,使它们处于当前表单大小所需的位置,然后Dock在两者上适当地设置属性。您希望侧面板的Dock属性设置为顶部、左侧和底部。您可能希望将主面板的Dock属性设置为 Top、Bottom、Left 和 Right(所有四个边)。当dock 属性设置正确时,控件将在调整窗体大小时自动调整自身大小。
After you have set the Dockproperty, you can test it by resizing the form right in the designer.
设置Dock属性后,您可以通过在设计器中调整表单大小来测试它。
回答by SSS
You might find it easier to use a SplitContainercontrol.
您可能会发现使用SplitContainer控件更容易。
For more complicated control layouts you can use a TableLayoutPanelto arrange your controls: set the TableLayoutPanel.Dockproperty to Fill, then set the .Anchorproperties of each control inside the TableLayoutPanel. There is a little arrow in the top right of the TableLayoutPanel(during design time) that allows you to specify the heights and widths of the rows and columns.
对于更复杂的控件布局,您可以使用 aTableLayoutPanel来排列您的控件:将TableLayoutPanel.Dock属性设置为Fill,然后.Anchor在TableLayoutPanel. TableLayoutPanel(在设计时)右上角有一个小箭头,允许您指定行和列的高度和宽度。

