tags:

views:

902

answers:

2

Hi there.

I have a number of panels in a single window in C# application and I created 2 scrollbars, one for horizontal and one vertical. This is what I currently have:

picture with 2 scroolbars

I have 1 variable and that is the total height all the items take & need. Here is my code on scroll change:

for (int i = 0; i < this._splitMainView.Panel2.Controls.Count; i++)
{
    this._splitMainView.Panel2.Controls[i].Location = new Point(
        3 - _scrollBarX.Value, 
        3 + (132 + 6) * (i - 2) - _scrollBarY.Value);
    this._splitMainView.Panel2.Controls[i].Refresh();
}

The scrollbar maximum is the total amount of all the containers height, the space in between and a few pixels extra.

As you can see from the picture, it doesn't look good. Even if the maximum in this case is a little around 50 - 100 pixels it still looks like it's a thousand pages long. When I change the SmallChange and LargeChange, the scrollbar bar itself lengthens but then it wont reach the maximum pixels. It will be able to get almost at the end (depening on the SmallChange and LargeChange value) and leave around 5 - 29 px left. And as everyone knows, seeing half is not good.

Does anyone know how to overcome this obstacle or a better way to implement it?

+1  A: 

Why not just make the maximum value of the scrollbar the overflow (visible area height - panel height)? Then just set the top of the panel to the value of the scrollbar * -1.

Robert C. Barth
A: 

Is there a reason not to use the AutoScroll property?

Fredrik Mörk