1

我对正在开发的程序有疑问。抱歉,如果我的帖子不是清晰易读,作为初学者编程完美主义者,我会尽可能清楚地解释所有内容。

我有一个名为 frmMain.vb 的 Windows 窗体,它有两个单独的面板,一个称为 sidebarPanel,另一个称为 mainPanel:

http://i.stack.imgur.com/Zs2lt.png

在运行时,表单是这样的:我缩小了屏幕以使其适合本主题,实际大小为 900、600,通过 frmMain_Load 中的此代码:

Me.Size = New Size(900, 600)

http://i.stack.imgur.com/gdA3z.png

现在我创建了以下代码:

With sidebarPanel
    .Top = 0
    .Left = 0
    .Width = 200
    .Height = 300
End With

With mainPanel
    .Top = 0
    .Left = 200
    .Width = 200
    .Height = 300
End With

如果你想知道侧边栏是怎么变成蓝色的,那部分来自一个 dll,那部分代码我为了让这个问题变得简单而省略了。如果仔细查看源代码,您会发现侧边栏的宽度为 200,主面板从左侧开始宽度为 200。

不碍事。我想知道答案,我在 Stackoverflow、Google 和一些 VB.NET 论坛上搜索过这些问题,但我似乎是一个孤独的人。

如何使侧边栏成为表单的 100% 高度,所以如果我调整大小,侧边栏也会改变高度。同样的问题也适用于主面板。

感谢您的阅读,感谢您的热情款待和回答。

4

2 回答 2

2

You can manually do so in the form's Resize event, by setting the Height property of the panels to Me.ClientSize.Height, however, it's easier to just do it all at design time.

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 Dock property appropriately on both. You want the side panel's Dock property to be set to Top, Left, and Bottom. You probably want the main panel's Dock property 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.

After you have set the Dock property, you can test it by resizing the form right in the designer.

于 2012-12-02T12:40:19.817 回答
1

SplitContainer您可能会发现使用控件更容易。

对于更复杂的控件布局,您可以使用 aTableLayoutPanel来排列控件:将TableLayoutPanel.Dock属性设置为Fill,然后.AnchorTableLayoutPanel. (在设计时)的右上角有一个小箭头TableLayoutPanel,可让您指定行和列的高度和宽度。

于 2012-12-03T00:49:00.317 回答