.NET:什么使我的表单在Show()上调整大小

时间:2012-08-31 07:32:28

标签: vb.net winforms

在显示表单之前,我的代码调整了它的大小,但是在调用它的Show()方法之后,它的大小既不是它在...中初始化的那个...也不是我刚设置它的那个。< / p>

我在其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

2 个答案:

答案 0 :(得分:0)

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

答案 1 :(得分:0)

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