1

Before showing a form my code adjusts its size, but after calling its Show() method it has a size that is neither the one it's initialized to in ...Designer.vb nor the one I just set it to.

I set a breakpoint in its Resize() handler, and the chain of calls from Show() to Resize() looks like this:

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   

I'm assuming there's some component with a Location and Size that force the Form to shape itself to their needs, but I can't really tell from the stack trace and I don't know how to find out what the cause is.

Any suggestions?

TIA

4

2 回答 2

0

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

于 2012-08-31T18:31:02.497 回答
0

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

于 2014-10-22T20:38:58.730 回答