Recent

Author Topic: Understanding TScrollBox's "range"  (Read 425 times)

Superdisk

  • Jr. Member
  • **
  • Posts: 73
Understanding TScrollBox's "range"
« on: August 12, 2022, 02:36:12 am »
I have a TScrollBox, and I'm trying to understand how a scroll bar's Range property works. The docs say it's "The virtual size of the Parent Control."

Not very descriptive... but the Delphi docs say:

Quote
Determines how far the scrolling region of the associated control can move.

Range represents the virtual size (in pixels) of the associated control's client area. 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.

Alright, so that should mean that if I do this:

Code: Pascal  [Select][+][-]
  1. ScrollBox1.VertScrollBar.Range := ScrollBox1.Height;

then there should be no scroll bar at all, as the virtual area inside the scroll box should be equal to the height of the container.

However, when I put a control inside a scroll box and use that line of code, it bizarrely makes a scroll bar that varies by some coefficient multiplied by the height of the scroll box!

I uploaded an example to show what I'm talking about. I'm not sure I understand the Range property.

dje

  • Full Member
  • ***
  • Posts: 134
Re: Understanding TScrollBox's "range"
« Reply #1 on: August 26, 2022, 11:50:43 am »
ScrollBox1.Height is the height of the entire control.
ScrollBox1.ClientHeight is the height of the inner client view. ie: Control height minus borders and visible scroll bars.
When you set VertScrollBar.Range, AutoScroll is turned off. So set Range to the size of your document size, and page to the client size.

Eg: If I have a bitmap which is 640x480, I'd setup the TScrollBox like:
Code: Pascal  [Select][+][-]
  1.   ScrollBox1.HorzScrollBar.Range := 640;
  2.   ScrollBox1.HorzScrollBar.Page := ScrollBox1.ClientWidth;
  3.   ScrollBox1.VertScrollBar.Range := 480;
  4.   ScrollBox1.VertScrollBar.Page := ScrollBox1.ClientHeight;  

 

TinyPortal © 2005-2018