Fandom

Delphi Programming

TScrollBar Class

2,918pages on
this wiki
Add New Page
Talk0 Share

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.

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

Standard TScrollBar

UnitEdit

HierarchyEdit

DescriptionEdit

This is essentially a wrapper for the standard windows scroll bar

Technical CommentsEdit

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

ExamplesEdit

Typical usage:Edit

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 AlsoEdit

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

User Comments/TipsEdit

(Please leave your name with your comment.)

Also on Fandom

Random Wiki