Controls changing size for no reason

froodley

Active member
Joined
Apr 20, 2010
Messages
26
Programming Experience
1-3
Hey, all,

Having another issue I'm hoping you can help with.

My program has two lists, one a listbox and the other a listview viewed in details mode.

Both of them change heights (get taller) for no obvious reason. I am having to add a call to a method that resizes them to the end of every method, which is kind of absurd, I think. Also, when the window size is changed, these components change size, which means I have to keep track of that.

What's going on here? :eek:

Edit: I had also thought of adding a timer to handle this. Which is fairly absurd, too :p
 

oliverg

Active member
Joined
Apr 14, 2010
Messages
37
Programming Experience
1-3
Check the properties windows for these controls.

Check:

Anchor
Dock
Width
Height

The properties window will give more information on the action of these values.
 

froodley

Active member
Joined
Apr 20, 2010
Messages
26
Programming Experience
1-3
Check the properties windows for these controls.

Check:

Anchor
Dock
Width
Height

The properties window will give more information on the action of these values.
Neither control is docked. Both are anchored. They change size along with everything else when the window size is changed.

They also change size for no reason as methods that fill or alter them are called.

The width and height are set in design view and should not be changing, except dynamically due to anchoring.
 

oliverg

Active member
Joined
Apr 14, 2010
Messages
37
Programming Experience
1-3
Have a look at the properties that have been set by the form designer, you can get to it from your solution explorer. Post the properties for the affected controls.
 

froodley

Active member
Joined
Apr 20, 2010
Messages
26
Programming Experience
1-3
Properties

The list box populates a good portion of the leftmost fourth of the form.

Its anchor is Top, Left, Bottom; its size is 159 by 468, and its dock is None.

The listview is smack in the middle.

Its anchor is Bottom, Left; its size is 346 by 205, and its dock is None.
 

oliverg

Active member
Joined
Apr 14, 2010
Messages
37
Programming Experience
1-3
if you expand the form on the solution explorer to reveal the form.designer.vb and the form.resx.

then double click the designer, scroll down the initializecomponent sub to where your affected controls are configured. Then paste this info.
 

oliverg

Active member
Joined
Apr 14, 2010
Messages
37
Programming Experience
1-3
You could put a breakpoint in the listview.resize event handler and check where abouts in your code the control is getting resized.
 

froodley

Active member
Joined
Apr 20, 2010
Messages
26
Programming Experience
1-3
Okay

Sorry, I didn't catch the gist of what you were asking for the first time...

the listbox:
VB.NET:
'lbBlah
        '
        Me.lbBlah.Anchor = CType(((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Bottom) _
                    Or System.Windows.Forms.AnchorStyles.Left), System.Windows.Forms.AnchorStyles)
        Me.lbBlah.Font = New System.Drawing.Font("Courier New", 9.75!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.lbBlah.FormattingEnabled = True
        Me.lbBlah.HorizontalScrollbar = True
        Me.lbBlah.ItemHeight = 16
        Me.lbBlah.Location = New System.Drawing.Point(9, 73)
        Me.lbBlah.Name = "lbBlah"
        Me.lbBlah.ScrollAlwaysVisible = True
        Me.lbBlah.Size = New System.Drawing.Size(159, 468)
        Me.lbBlah.TabIndex = 7
The listview:

VB.NET:
        'lvBlah
        '
        Me.lvBlah.Anchor = CType((System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Left), System.Windows.Forms.AnchorStyles)
        Me.lvBlah.CheckBoxes = True
        Me.lvBlah.Columns.AddRange(New System.Windows.Forms.ColumnHeader() {Me.colNum, Me.colStatic, Me.colKinetic})
        Me.lvBlah.Font = New System.Drawing.Font("Courier New", 8.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.lvBlah.FullRowSelect = True
        Me.lvBlah.GridLines = True
        Me.lvBlah.HeaderStyle = System.Windows.Forms.ColumnHeaderStyle.Nonclickable
        Me.lvBlah.HideSelection = False
        Me.lvBlah.Location = New System.Drawing.Point(21, 285)
        Me.lvBlah.Name = "lvBlah"
        Me.lvBlah.ShowGroups = False
        Me.lvBlah.Size = New System.Drawing.Size(346, 205)
        Me.lvBlah.TabIndex = 13
        Me.lvBlah.UseCompatibleStateImageBehavior = False
        Me.lvBlah.View = System.Windows.Forms.View.Details
 

froodley

Active member
Joined
Apr 20, 2010
Messages
26
Programming Experience
1-3
ahhh.

didn't think of breaking there, great idea. hopefully that will make some sense of it.
 

oliverg

Active member
Joined
Apr 14, 2010
Messages
37
Programming Experience
1-3
There is nothing obvious to me, I'd try watching the Resized events for these controls and maybe this will shed some light onto the problem.

Select the resized event from the properties pane, double click it and the code should pop into your form class.

add a breakpoint in the event by clicking the grey area to the left of the code.

When the item is resized, this will pause the code and you can have a look at the current situation in a bit more detail to find the problem.
 

froodley

Active member
Joined
Apr 20, 2010
Messages
26
Programming Experience
1-3
hmmm

Thanks, I gave that a shot. I have slightly more detail: this happens most reliably if I minimize the window. The listbox resize event is called a bunch of times in a row; the listview resize is only called once or twice. The stack traces for the undesired resizes indicate it's nothing in my code:

VB.NET:
OnResize    at blah.frmMain.lbTests_Resize()
   at blah.frmMain._Lambda$__6(Object a0, EventArgs a1)
   at System.Windows.Forms.Control.OnResize(EventArgs e)
   at System.Windows.Forms.ListBox.OnResize(EventArgs e)
   at System.Windows.Forms.Control.OnSizeChanged(EventArgs e)
   at System.Windows.Forms.Control.UpdateBounds(Int32 x, Int32 y, Int32 width, Int32 height, Int32 clientWidth, Int32 clientHeight)
   at System.Windows.Forms.Control.UpdateBounds()
   at System.Windows.Forms.Control.WndProc(Message& m)
   at System.Windows.Forms.ListBox.WndProc(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
   at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
   at System.Windows.Forms.UnsafeNativeMethods.CallWindowProc(IntPtr wndProc, IntPtr hWnd, Int32 msg, IntPtr wParam, IntPtr lParam)
   at System.Windows.Forms.NativeWindow.DefWndProc(Message& m)
   at System.Windows.Forms.Control.DefWndProc(Message& m)
   at System.Windows.Forms.Control.WmWindowPosChanged(Message& m)
   at System.Windows.Forms.Control.WndProc(Message& m)
   at System.Windows.Forms.ListBox.WndProc(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
   at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
   at System.Windows.Forms.UnsafeNativeMethods.CallWindowProc(IntPtr wndProc, IntPtr hWnd, Int32 msg, IntPtr wParam, IntPtr lParam)
   at System.Windows.Forms.NativeWindow.DefWndProc(Message& m)
   at System.Windows.Forms.Control.DefWndProc(Message& m)
   at System.Windows.Forms.Control.WndProc(Message& m)
   at System.Windows.Forms.ListBox.WndProc(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
   at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
   at System.Windows.Forms.UnsafeNativeMethods.CallWindowProc(IntPtr wndProc, IntPtr hWnd, Int32 msg, IntPtr wParam, IntPtr lParam)
   at System.Windows.Forms.NativeWindow.DefWndProc(Message& m)
   at System.Windows.Forms.Control.DefWndProc(Message& m)
   at System.Windows.Forms.Control.WmWindowPosChanged(Message& m)
   at System.Windows.Forms.Control.WndProc(Message& m)
   at System.Windows.Forms.ListBox.WndProc(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
   at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
   at System.Windows.Forms.SafeNativeMethods.SetWindowPos(HandleRef hWnd, HandleRef hWndInsertAfter, Int32 x, Int32 y, Int32 cx, Int32 cy, Int32 flags)
   at System.Windows.Forms.Control.SetBoundsCore(Int32 x, Int32 y, Int32 width, Int32 height, BoundsSpecified specified)
   at System.Windows.Forms.ListBox.SetBoundsCore(Int32 x, Int32 y, Int32 width, Int32 height, BoundsSpecified specified)
   at System.Windows.Forms.Control.System.Windows.Forms.Layout.IArrangedElement.SetBounds(Rectangle bounds, BoundsSpecified specified)
   at System.Windows.Forms.Layout.DefaultLayout.ApplyCachedBounds(IArrangedElement container)
   at System.Windows.Forms.Layout.DefaultLayout.xLayout(IArrangedElement container, Boolean measureOnly, Size& preferredSize)
   at System.Windows.Forms.Layout.DefaultLayout.LayoutCore(IArrangedElement container, LayoutEventArgs args)
   at System.Windows.Forms.Layout.LayoutEngine.Layout(Object container, LayoutEventArgs layoutEventArgs)
   at System.Windows.Forms.Control.OnLayout(LayoutEventArgs levent)
   at System.Windows.Forms.ScrollableControl.OnLayout(LayoutEventArgs levent)
   at System.Windows.Forms.Form.OnLayout(LayoutEventArgs levent)
   at System.Windows.Forms.Control.PerformLayout(LayoutEventArgs args)
   at System.Windows.Forms.Control.System.Windows.Forms.Layout.IArrangedElement.PerformLayout(IArrangedElement affectedElement, String affectedProperty)
   at System.Windows.Forms.Layout.LayoutTransaction.DoLayout(IArrangedElement elementToLayout, IArrangedElement elementCausingLayout, String property)
   at System.Windows.Forms.Control.OnResize(EventArgs e)
   at System.Windows.Forms.Form.OnResize(EventArgs e)
   at System.Windows.Forms.Control.OnSizeChanged(EventArgs e)
   at System.Windows.Forms.Control.UpdateBounds(Int32 x, Int32 y, Int32 width, Int32 height, Int32 clientWidth, Int32 clientHeight)
   at System.Windows.Forms.Control.UpdateBounds()
   at System.Windows.Forms.Control.WndProc(Message& m)
   at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
   at System.Windows.Forms.ContainerControl.WndProc(Message& m)
   at System.Windows.Forms.Form.WndProc(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
   at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
   at System.Windows.Forms.UnsafeNativeMethods.CallWindowProc(IntPtr wndProc, IntPtr hWnd, Int32 msg, IntPtr wParam, IntPtr lParam)
   at System.Windows.Forms.NativeWindow.DefWndProc(Message& m)
   at System.Windows.Forms.Form.DefWndProc(Message& m)
   at System.Windows.Forms.Control.WmWindowPosChanged(Message& m)
   at System.Windows.Forms.Control.WndProc(Message& m)
   at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
   at System.Windows.Forms.ContainerControl.WndProc(Message& m)
   at System.Windows.Forms.Form.WmWindowPosChanged(Message& m)
   at System.Windows.Forms.Form.WndProc(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
   at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
   at System.Windows.Forms.UnsafeNativeMethods.CallWindowProc(IntPtr wndProc, IntPtr hWnd, Int32 msg, IntPtr wParam, IntPtr lParam)
   at System.Windows.Forms.NativeWindow.DefWndProc(Message& m)
   at System.Windows.Forms.Form.DefWndProc(Message& m)
   at System.Windows.Forms.Control.WndProc(Message& m)
   at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
   at System.Windows.Forms.ContainerControl.WndProc(Message& m)
   at System.Windows.Forms.Form.WmSysCommand(Message& m)
   at System.Windows.Forms.Form.WndProc(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
   at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
   at System.Windows.Forms.UnsafeNativeMethods.CallWindowProc(IntPtr wndProc, IntPtr hWnd, Int32 msg, IntPtr wParam, IntPtr lParam)
   at System.Windows.Forms.NativeWindow.DefWndProc(Message& m)
   at System.Windows.Forms.Form.DefWndProc(Message& m)
   at System.Windows.Forms.Control.WndProc(Message& m)
   at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
   at System.Windows.Forms.ContainerControl.WndProc(Message& m)
   at System.Windows.Forms.Form.WmNcButtonDown(Message& m)
   at System.Windows.Forms.Form.WndProc(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
   at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
   at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
   at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
   at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
   at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
   at System.Windows.Forms.Application.Run(ApplicationContext context)
   at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun()
   at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel()
   at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(String[] commandLine)
   at blah.My.MyApplication.Main(String[] Args)
   at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
   at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
   at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
   at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Threading.ThreadHelper.ThreadStart()
... but beyond that, nothing much to me. Perhaps someone here can shed more light on the subject?

If I handle this by using frmMain.resize to reset the size of the listboxes, is there some way I can know if the resize was caused by the minimize button/restore, and not by maximize or user-defined resize?
 

mbb

Well-known member
Joined
Jun 3, 2009
Messages
52
Programming Experience
10+
Do you have a menu or status strip on your form? Its not actually part of the form but a control that takes up space on the form. I've had an issue like this where the form resizes controls to take into account the menu or status strip being shown or hidden, IIRC.

I sorted this out by putting a panel on the form which represented the 'work area' of the form, and then put my controls onto the panel.
 

froodley

Active member
Joined
Apr 20, 2010
Messages
26
Programming Experience
1-3
Nope...

No menu or status strip.

The listview is in a panel (the "main" area), and the listbox is not.

Thanks, though... I'll think about what else might be resizing.
 

froodley

Active member
Joined
Apr 20, 2010
Messages
26
Programming Experience
1-3
*sigh*

I tried to handle wndProc, but the resize is happening somewhere in between when the message is sent and the next time the listbox's resize event is raised.

I think I'm going to give up and just disallow resizing the window so I can force it to stay one size by smashing it back into shape whenever it tries to resize... kind of a hack...
 

servantofone

Member
Joined
Apr 20, 2010
Messages
13
Programming Experience
5-10
I had a similar issue once when I changed the font at runtime. As soon as I commented out the font change, the resizing stopped. Are you making any cosmetic changes to the form at runtime? If so, try commenting them out and see if the issue continues. Mine had something to do with System.Drawing... It was quite annoying.
 
Top Bottom