.net scrollbar autoscroll problem

14,155

Solution 1

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.

Solution 2

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

Solution 3

I haven't noticed exactly the behavior you describe, but have run into situations where the appearance of the vertical scrollbar makes a horizontal scrollbar necessary.

You could set the contents of the panel to allow for the width of the scrollbar, for example if I have a ListBox in a Panel:

listBox1.Width = panel2.Width - System.Windows.Forms.SystemInformation.VerticalScrollBarWidth;

HTH

Share:
14,155
Matthias Wandel
Author by

Matthias Wandel

Updated on July 25, 2022

Comments

  • Matthias Wandel
    Matthias Wandel almost 2 years

    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?

  • Matthias Wandel
    Matthias Wandel over 13 years
    Well, I was looking at xnview for what I wanted to do, and xnview has the behaviour done very well. But I suspect they didn't use the autoscroll functionality. But autoscroll is just so darned handy, too bad it doesn't quite work right. Too bad Microsoft couldn't get it right. disappointing that Microsoft didn't.
  • user1703401
    user1703401 over 13 years
    Not sure what that means. But yes, this won't go wrong when auto-scroll is not supported by a library. If only windows had their scrollbars outside of the window, it would have never been a problem. I nevertheless really liked them trying to make it work.
  • Matthias Wandel
    Matthias Wandel over 13 years
    This is what I ended up doing as well, but I ran into problems where one scrollbar stayed around until both disappeared. Which is the nature of my problem. I eventually gave up trying to get windows to do the right thing and stopped using the autoscroll feature.