Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.net scrollbar autoscroll problem

I'm writing an app in .net that uses the autoscroll for a layout panel in a dialog. It seems that whenever I resize the window so that the vertical scrollbars should appear, the horizontal scrollbar automatically appears also. Looking closely at it, the second scrollbar now allows me to scroll the window by 16 pixels (the width of the other scrollbar). So windows seems to think I need a client area that is at least as wide as it was before the vertical scrollbar appeared.

If I now resize the window to be 16 pixels wider (so that my window area is as wide as it was before the scrollbar appeared), the scrollbar goes away. Now if I resize it back down to what it was, it stays away.

So it would appear to me that there is a bug in the system where the minimum width is somehow sticky, but upsizing and downsizging the window (with the mouse, and without tuching the scrollbars related APIs) clears the condition

Does anybody know of a workaround, or am I doing something to trip up Windows?

like image 443
Matthias Wandel Avatar asked Sep 27 '10 15:09

Matthias Wandel


2 Answers

Yes, I think you already diagnosed the problem correctly. It is a nasty side effect of, say, the vertical scrollbar appearing and needing space, making the available client area smaller. Too small to fit the controls, now also making the horizontal scrollbar appear. It is actually bi-stable, the horizontal bar can flicker on and off in certain cases.

To avoid this effect, the layout engine would have to make multiple passes through the layout, dealing with the changing client area. It however only makes one pass. Which sounds wise, this could be a potentially never ending loop. I don't know of a decent fix for this. Your user will probably just resize the window large enough to get rid of at least one of the scrollbars.

like image 164
Hans Passant Avatar answered Sep 23 '22 04:09

Hans Passant


This is a known bug in windows - here

Best way to fix this is to put the table layout panel autosized inside another panel which is docked to the main form and set with autoscroll = true

So you are no longer using the tablelayoutpanel to scroll which is buggy, you use the panel to scroll and the tablelayoutpanel is inside the panel

like image 30
Lance Avatar answered Sep 21 '22 04:09

Lance