Delphi Programming
Advertisement
Info
see the VCL Documentation Guidelines for an overview on doc pages

Standard TScrollBar

Unit[]

Hierarchy[]

Description[]

This is essentially a wrapper for the standard windows scroll bar

Technical Comments[]

(Known issues / Documentation clarifications / Things to be aware of)

Examples[]

Typical usage:[]

to add a scroll bar to the right of your own text box class

         cActiveText = class( TCustomControl )  // ie a TWinControl descendant
           public
             constructor  Create( sender : TObject; form : TForm );
           private
             mScroller :  TScrollBar;
             procedure    ATScrollerScroll(Sender: TObject; ScrollCode: TScrollCode; var ScrollPos: Integer);

in the create method

       constructor  cActiveText.Create( sender : TObject; form : TForm );
         begin
         inherited Create( form );
         ....
         Top := 100;           // set your canvas size
         Left := 0;
         Width := mForm.ClientWidth;
         Height := mForm.ClientHeight - 100;
         mScroller := TScrollBar.Create( form );  // create here ( not on the form at design time )
         mScroller.Parent := self;
         mScroller.Kind := sbVertical;
         mScroller.Align := alRight;
         mScroller.OnScroll := ATScrollerScroll;  // handle the scroll event
         end;
       procedure    cActiveText.ATScrollerScroll(Sender: TObject; ScrollCode: TScrollCode;
                                         var ScrollPos: Integer);
         begin
         Invalidate;
         end;

when adding text to be displayed

       function     cActiveText.NewLine() : integer;
         begin
         mScroller.Hide;
         mScroller.PageSize := 1;  // to avoid unpleasantness
         Inc( mNLines );           // line count
         mScroller.SetParams( 1, 1, mNLInes );  // set scroller position, min and max
         Invalidate;
         end;

when painting

       procedure    cActiveText.Paint;
         dyText := Canvas.TextHeight( '_A' );
         dyLine := dyText + 4;
         lines := Height div dyLine;       // calculate displayable lines
         if Height <= mNLines * dyLine then  begin   // too many lines to fit on the screen
           mScroller.LargeChange := lines;            // set page up/down to number of screen lines
           mScroller.PageSize := lines;               // and the scroller tab
           FirstLine := mScroller.Position;
           mScroller.Show;
           end
         else  mScroller.Hide;           // if it fits hide the scrollbar
         TextOut( Lines[ FirstLine )     // paint from

See Also[]

(Please provide links to items specifically related to this item.)

User Comments/Tips[]

(Please leave your name with your comment.)

Advertisement