.NET:是什么让我的Form在Show()上调整大小



在显示窗体之前,我的代码会调整其大小,但在调用其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   

我假设有一些组件的位置和大小会迫使Form根据自己的需求进行调整,但我真的无法从堆栈跟踪中判断出来,也不知道如何找出原因。

有什么建议吗?

TIA

您的AutoScaleMode设置为默认值Font,并且您指定了一个比Windows默认值更大(或更小)的字体。

我怀疑表单的初始大小很小,这将导致您看到的行为。如果是,请给表单一个等于初始大小的MinimumSize(而不是0,0)。如果您还没有提供最小大小,那么在调用GetClientRect()和GetWindowRect(()时(在调用UpdateBounds()期间),它似乎是根据您的环境为您计算的。对我来说,这是113x28。

最新更新