Alex Rivera | Logout

.net scrollbar autoscroll problem

Asked 2010-09-27T15:32:04.243
9

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?

Edit
Report

1 Answer

1

I just encountered this issue. The fix I used was to set Scrollable to false and then to true. Here is an example with a ListView Resize event:

private void myListView_Resize(object sender, EventArgs e)
{
 this.SuspendLayout();

 //Code to do various resizing stuff

 //Force Scrollbar Recalculation
 myListView.Scrollable = false;
 myListView.Scrollable = true;
 this.ResumeLayout(false);
 this.PerformLayout();
}

If Scrollable is not always true, you can make the recalculation conditional.

answered 2010-10-01T19:36:18.807

Your Answer