简体   繁体   English

VB.NET-面板内部的窗体调整大小

[英]VB.NET - form inside a panel resize

I can't figure this out! 我不知道这个! I've researched docking, anchoring etc. but I'm yet to get it to correctly resize when the parent form resizes. 我已经研究了停靠,锚定等问题,但是当父窗体调整大小时,我还没有使其正确调整大小。

Edit: 编辑:

Quick Overview: 快速概述:

I have a main form with a menustrip docked to the top and a panel set to fill. 我有一个主菜单,菜单栏停靠在顶部,面板设置为要填充。 I have links within the menustrip which open forms within the panel. 我在菜单栏中有链接,可在面板内打开表单。 See code below. 请参见下面的代码。 I am struggling to get the form within the panel to resize with the panel. 我正在努力让面板中的表格与面板一起调整大小。

I've set the panel background to black and my form inside the panel to white. 我将面板背景设置为黑色,并将面板内部的窗体设置为白色。 I can see the panel resizing with the form correctly. 我可以看到面板正确调整了表单的大小。 The form within the panel stays in its original position. 面板中的表格保持其原始位置。 If i start my app in maximized, then click on my menustrip sure enough the form within the panel resizes correctly. 如果我以最大化的速度启动我的应用程序,请单击菜单栏上的,确保面板中的表单正确调整大小。 However, once it is maximized it doesn't shrink with the form like the panel container does. 但是,一旦最大化,它就不会像面板容器那样收缩。

I've deleted everything on my whole form, added 1 panel to it and set to fill then on form load do the following: 我已经删除了整个表单中的所有内容,并向其中添加了1个面板并设置为fill,然后在表单加载时执行以下操作:

Dim f As New Contactdetails With {.TopLevel = False, .AutoSize = True}
    f.Dock = DockStyle.Fill
    Me.Panel2.Controls.Add(f)
    f.Show()

This still doesn't work. 这仍然行不通。 When i maximize my main form, the form inside the panel does not resize but the panel does as i've changed it's background to monitor its change in size 当我最大化主窗体时,面板内的窗体不会调整大小,但是面板会按照我的更改进行调整,以监视其大小的背景变化

Turn AutoSize off: 关闭自动调整大小:

Dim f As New Contactdetails With {.TopLevel = False, .AutoSize = False}
f.Dock = DockStyle.Fill
Me.Panel2.Controls.Add(f)
f.Show()

If the previous form in the panel isn't being used anymore, then you should first dispose of it: 如果不再使用面板中的上一个表格,则应首先处理它:

While Me.Panel2.Controls.Count > 0
  Me.Panel2.Controls(0).Dispose()
End While

Set the WindowState to Normal in properties of the child form 在子窗体的属性中将WindowState设置为Normal

and

Me.Dock = DockStyle.

Fill in the Load sub of the child form 填写子表单的“加载”子项

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM