How do I make the scroll bars show up on a TScrollBox?

15.2k Views Asked by At

The TScrollBox control looks like it's supposed to basically be a TPanel with scroll bars attached along the bottom and the right edge. I tried placing one on a form, but no matter what I do, I can't make the scroll bars actually appear, either at design-time or at runtime. Does anyone know how to make them show up?

3

There are 3 best solutions below

2
Nick Dandoulakis On BEST ANSWER

Set AutoScroll property to True.
Now if you add controls that clip the box borders, the bars will appear.

0
RRUZ On

Mason

You can't see the scrolling bars until there's actually something to scroll to.

To see the scrollbars try this

1.Set the BorderStyle property of the Form to bsSingle

2.Insert a button in a form

3.Put a scrollbar in a form

4.Set the Align property of the TScrollBox to alClient

5.Run this code in a button click

procedure TForm10.Button1Click(Sender: TObject);
Var
i : integer;
ed : TEdit;
begin
           for i:=1 to 30 do
           Begin
              ed:=TEdit.Create(self);
              ed.Parent:=ScrollBox1;
              ed.Top:=5+((i-1)*30);
              ed.Left:=10;
              ed.Width:=100;
              ed.Text:='Editext'+ IntToStr(i);
           End;
end;

Bye.

0
Uli Gerhardt On

If I'm not mistaken (no Delphi around to check) it suffices to set HorzScrollBar.Range big enough.

EDIT: IIUC this DFM does what you want - entirely at design-time:

object Form1: TForm1
  Left = 0
  Top = 0
  Caption = 'Form1'
  ClientHeight = 206
  ClientWidth = 312
  Color = clBtnFace
  ParentFont = True
  OldCreateOrder = True
  PixelsPerInch = 96
  TextHeight = 13
  object ScrollBox1: TScrollBox
    Left = 8
    Top = 8
    Width = 150
    Height = 150
    HorzScrollBar.Range = 300
    VertScrollBar.Range = 300
    AutoScroll = False
    TabOrder = 0
  end
end