views:

393

answers:

3

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  A: 

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

Nick D
OK, it looks like I've got the wrong control, then. I need scroll bars that can be controlled programmatically, based off other factors than the sizes and positions of the controls inside the box.
Mason Wheeler
@Mason Wheeler, in case you don't find a proper control for your task, an *ugly* solution will be to place a panel inside the scroll box. By resizing the panel you can adjust the scroll bars. Any other control must reside on that panel. Of course, if you need more control, you can always use TScrollBar controls.
Nick D
+2  A: 

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.

RRUZ
A: 

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
Ulrich Gerhardt