Vb.net .NET:是什么让我的表单在Show上调整大小()

Vb.net .NET:是什么让我的表单在Show上调整大小(),vb.net,winforms,Vb.net,Winforms,在显示窗体之前,我的代码会调整其大小,但在调用其Show()方法之后,它的大小既不是在…Designer.vb中初始化为的大小,也不是我刚刚设置的大小 我在其Resize()处理程序中设置了一个断点,从Show()到Resize()的调用链如下所示: MyApp.exe!MyApp.SearchListForm.frmSearchList_Resize(Object eventSender, System.EventArgs eventArgs) Line 2256 Basic System

在显示窗体之前,我的代码会调整其大小,但在调用其Show()方法之后,它的大小既不是在…Designer.vb中初始化为的大小,也不是我刚刚设置的大小

我在其Resize()处理程序中设置了一个断点,从Show()到Resize()的调用链如下所示:

MyApp.exe!MyApp.SearchListForm.frmSearchList_Resize(Object eventSender, System.EventArgs eventArgs) Line 2256   Basic
System.Windows.Forms.dll!System.Windows.Forms.Control.OnResize(System.EventArgs e) + 0xbb bytes 
System.Windows.Forms.dll!System.Windows.Forms.Form.OnResize(System.EventArgs e) + 0xd bytes 
System.Windows.Forms.dll!System.Windows.Forms.Control.OnSizeChanged(System.EventArgs e) + 0x29 bytes    
System.Windows.Forms.dll!System.Windows.Forms.Control.UpdateBounds(int x, int y, int width, int height, int clientWidth, int clientHeight) + 0x9c bytes 
System.Windows.Forms.dll!System.Windows.Forms.Control.UpdateBounds() + 0xd1 bytes   
System.Windows.Forms.dll!System.Windows.Forms.Control.WmCreate(ref System.Windows.Forms.Message m) + 0x29 bytes 
System.Windows.Forms.dll!System.Windows.Forms.Control.WndProc(ref System.Windows.Forms.Message m) + 0x2e7 bytes 
System.Windows.Forms.dll!System.Windows.Forms.ScrollableControl.WndProc(ref System.Windows.Forms.Message m) + 0x2a bytes    
System.Windows.Forms.dll!System.Windows.Forms.ContainerControl.WndProc(ref System.Windows.Forms.Message m) + 0x10 bytes 
System.Windows.Forms.dll!System.Windows.Forms.Form.WmCreate(ref System.Windows.Forms.Message m) + 0xe bytes 
System.Windows.Forms.dll!System.Windows.Forms.Form.WndProc(ref System.Windows.Forms.Message m) + 0x193 bytes    
System.Windows.Forms.dll!System.Windows.Forms.Control.ControlNativeWindow.OnMessage(ref System.Windows.Forms.Message m) + 0x10 bytes    
System.Windows.Forms.dll!System.Windows.Forms.Control.ControlNativeWindow.WndProc(ref System.Windows.Forms.Message m) + 0x31 bytes  
System.Windows.Forms.dll!System.Windows.Forms.NativeWindow.DebuggableCallback(System.IntPtr hWnd, int msg, System.IntPtr wparam, System.IntPtr lparam) + 0x57 bytes 
[Native to Managed Transition]  
[Managed to Native Transition]  
System.Windows.Forms.dll!System.Windows.Forms.UnsafeNativeMethods.CreateWindowEx(int dwExStyle, string lpszClassName, string lpszWindowName, int style, int x, int y, int width, int height, System.Runtime.InteropServices.HandleRef hWndParent, System.Runtime.InteropServices.HandleRef hMenu, System.Runtime.InteropServices.HandleRef hInst, object pvParam) + 0x3c bytes  
System.Windows.Forms.dll!System.Windows.Forms.NativeWindow.CreateHandle(System.Windows.Forms.CreateParams cp) + 0x225 bytes 
System.Windows.Forms.dll!System.Windows.Forms.Control.CreateHandle() + 0x125 bytes  
System.Windows.Forms.dll!System.Windows.Forms.Form.CreateHandle() + 0x9f bytes  
System.Windows.Forms.dll!System.Windows.Forms.Control.Handle.get() + 0x45 bytes 
System.Windows.Forms.dll!System.Windows.Forms.Form.SetVisibleCore(bool value) + 0x160 bytes 
System.Windows.Forms.dll!System.Windows.Forms.Control.Show() + 0x10 bytes   
我假设某个组件的位置和大小会迫使窗体根据其需要自行调整形状,但我无法从堆栈跟踪中真正分辨出来,也不知道如何找出原因

有什么建议吗


TIA

您的AutoScaleMode设置为默认值
Font
,您指定的字体比Windows默认值大(或小)。

我怀疑您的表单的初始大小很小-这将导致您看到的行为。如果是,请为表单指定与初始大小相等的最小大小(0,0除外)。如果尚未提供最小大小,则在根据您的环境调用GetClientRect()和GetWindowRect()时(在调用UpdateBounds()期间),似乎会为您计算最小大小。对我来说,这是113x28

您的表单是否将autosize属性设置为true?autosize和AutoScale都为false此问题是否有解决方案?我也有同样的问题。“自动大小”和“自动缩放”均为false,窗口没有边框、标题、最小化/最大化按钮或菜单。但是,当调用UpdateBounds()时,UnsafentaviveMethods.GetClientRect()和UnsafentaviveMethods.GetWindowRect()返回的大小太大,并且在代码或资源文件中的任何位置都没有定义。或者更常见的情况是:视频适配器具有不同的DPI设置。AutoSize和AutoScale都为False,但AutoScaleMode为Inherit。如果“自动缩放”为False,我不确定AutoScaleMode有什么影响(如果有)。碰巧的是,表单的形状变得越来越窄,越来越高,底部有一个很大的空白区域,所以我真的不知道缩放到某个字体大小或屏幕分辨率会导致什么。可能值得一提的是,AutoSizeChanged,永远不会引发MaximumBoundsChanged和MaximumSizeChanged事件。通过设置AutoScaleMode一次性排除它。无