Glen Morse
Glen Morse

Reputation: 2593

understanding ScrollBox Range

I dont understand how to adjust the range of a scrollbar. Say I have image1 : TImage; inside a TScrollingWinControl component.

Now to start I make the range = to the default size of the componet like so.

  width := Image1.width ;
  height := Image1.Height;
  HorzScrollBar.Range := Image1.Width;  
  VertScrollBar.Range := Image1.Height;

Up to here I belive I am good. Everything looks good, No scrolling bars will show up like i want. Now I Make only the image bigger, but component stays same size Like so.

 Image1.height := Image1.Height +100;
 Image1.Width  := Image1.Width  +200;

Now I can tell my image is bigger and the component is same size but the scroll bars never show. So For them to show i need to set the range, This confuses me as

  1. if the Range of a form's Vertical scroll bar is set to 500, and the Height of the form is 200, the scroll bar's Position can vary from 0 to 300.

So here is where i am confused, do i Take the image1.height - Component height and set that as range? or is the range the whole Image1.height and the scrollbar does the subtracting?

Upvotes: 1

Views: 5674

Answers (1)

David Heffernan
David Heffernan

Reputation: 613412

The scroll box does not adapt itself to its contents when their dimensions change. You must do that. After all, what if you want the scroll bar to scroll only part of the content into view. So you need to keep the Range property in sync with the dimensions of the controls contained in the scroll box.

From the documentation:

Range represents the virtual size (in pixels) of the associated control's client area.

So, you simply need to set the Range property to be equal to the size of your image. If the size of your image changes you need to update the ranges like this:

HorzScrollBar.Range := Image1.Width;  
VertScrollBar.Range := Image1.Height;

The documentation goes on to say:

For example, if the Range of a form's horizontal scroll bar is set to 500, and the width of the form is 200, the scroll bar's Position can vary from 0 to 300.

You seem confused by this. I think you wonder why the position varies from 0 to 300. Well, when the position is 0 the visible area is 0 to 200. When the position is 300 the visible area is 300 to 500. Thus the full range is covered. But the scroll box control takes care of managing the scroll bars. You simply need to set the ranges to be the size of the image.

Upvotes: 6

Related Questions