Scroll Label Demo (TWpLabel aka TScrollLabel) lazarus / 31-LCL ---------------------------------------------------------------------- RAW · 2019-07-30 14:30 I know this little control isn't part of the LCL, but I think it's incredible useful (especially with a classic theme) and it could be part of it. Anyway this way it's easier to find it I guess... Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i UNIT uScrollLabelBasic;{$MODE OBJFPC}{$H+}INTERFACE USES  Classes,  Controls,  Graphics; TYPE  TScrollLabelBasic = Class(TGraphicControl)   PROTECTED    Procedure Resize; Override;   PRIVATE    slItems    : TStrings;    iTopLine   : Integer;    iItemHeight: Integer;    iAddHeight : Integer; // additional space between text and top/bottom (sum)    iTextPos   : Integer;    iTextLeft  : Integer;    bsBrush    : TBrushStyle;    booResize  : Boolean;    Function  GetCaption   : String;    Procedure SetCaption   (Const str: String);    Function  GetFont      : TFont;    Procedure SetFont      (Const Ft: TFont);  Procedure SetItems     (Const sl: TStrings);    Procedure SetBrush   (Const bs: TBrushStyle);    Procedure SetAddHeight (Const i: Integer);    Procedure SetTextLeft  (Const i: Integer);   PUBLIC    Constructor Create           (AOwner: TComponent); Override;    Destructor  Destroy;         Override;    Procedure   Paint;         Override;    Function    ItemsPerPage     : Integer;    Procedure   TextPos          (Const i: Integer; booPaint: Boolean);    Procedure ScrollBy         (i: Integer);    Procedure   ScrollTo         (i: Integer);    Procedure   MouseWheelScroll (iMaxLine, iScroll: Integer;                                  Shift: TShiftState; WheelDelta: Integer);    Procedure  KeyboardVkRight (iMaxLine, iScroll: Integer; Shift: TShiftState);    Procedure  KeyboardVkLeft  (iScroll: Integer; Shift: TShiftState);   PUBLISHED    Property Color;    Property TopLine: Integer Read iTopLine;    Property AddHeight: Integer Read iAddHeight Write SetAddHeight Default 0;    Property TextLeft: Integer Read iTextLeft Write SetTextLeft Default 0;    Property Items: TStrings Read slItems Write SetItems;    Property Font: TFont Read GetFont Write SetFont;    Property Caption: String Read GetCaption Write SetCaption;    Property BrushStyle: TBrushStyle Read bsBrush Write SetBrush;    Property OnMouseMove;    Property OnMouseDown;    Property OnResize;  End; IMPLEMENTATION Constructor TScrollLabelBasic.Create(AOwner: TComponent);Begin  Inherited;  slItems:= TStringList.Create;End; Destructor TScrollLabelBasic.Destroy;Begin  slItems.Free;  Inherited;End; Function TScrollLabelBasic.GetCaption: String;Begin  Result:= slItems.Text;End; Procedure TScrollLabelBasic.SetCaption(Const str: String);Begin  slItems.Text:= str;  iTopLine:= 0;  iTextPos:= iTextLeft;  Invalidate;End; Function TScrollLabelBasic.GetFont: TFont;Begin  Result:= Inherited Font;End; Procedure TScrollLabelBasic.SetFont(Const Ft: TFont);Begin  Inherited Font:= Ft;  Canvas.Font:= Ft;  iItemHeight:= Canvas.TextHeight('Û')+4+iAddHeight;End; Procedure TScrollLabelBasic.SetItems(Const sl: TStrings);Begin  slItems.Assign(sl);  iTopLine:= 0;  iTextPos:= iTextLeft;  Invalidate;End; Function TScrollLabelBasic.ItemsPerPage: Integer;Begin  Result:= Height Div iItemHeight;End; Procedure TScrollLabelBasic.SetAddHeight(Const i: Integer);Begin  iAddHeight:= i;  Invalidate;End; Procedure TScrollLabelBasic.SetBrush(Const bs: TBrushStyle);Begin  bsBrush:= bs;  Invalidate;End; Procedure TScrollLabelBasic.SetTextLeft(Const i: Integer);Begin  iTextLeft:= i;  Invalidate;End; Procedure TScrollLabelBasic.TextPos(Const i: Integer; booPaint: Boolean);Begin  iTextPos:= i;  If booPaint Then Invalidate;End; Procedure TScrollLabelBasic.Paint;Var i, iy: Integer;Begin  Canvas.Font.Assign(Font);  If iItemHeight = 0  Then iItemHeight:= Canvas.TextHeight('Û')+4+iAddHeight;  booResize:= True;   Canvas.Brush.Style:= bsBrush;   If (Canvas.Brush.Style <> bsClear)   Then    Begin      Canvas.Brush.Color:= Color;      Canvas.FillRect(Rect(0, 0, Width, Height));    End;    i:= iTopLine;   iy:= 0;   While (iy < Height) And (i < slItems.Count)  Do   Begin    Canvas.TextOut(iTextPos, iy+2+(iAddHeight SHR 1), slItems[i]);    Inc(iy, iItemHeight);    Inc(i);   End;End; Procedure TScrollLabelBasic.ScrollTo(i: Integer);Begin  If slItems.Count <= ItemsPerPage Then Exit;  If i < 0 Then i:= 0  Else   Begin    If i+ItemsPerPage >= slItems.Count    Then i:= slItems.Count- ItemsPerPage;   End;  iTopLine:= i;  Invalidate;End; Procedure TScrollLabelBasic.ScrollBy(i: Integer);Begin  ScrollTo(iTopLine+i);End; Procedure TScrollLabelBasic.Resize;Begin  Inherited Resize;  If booResize  Then   Begin     iTextPos:= iTextLeft;     If slItems.Count <= ItemsPerPage     Then      Begin     iTopLine:= 0;       Invalidate;      End     Else ScrollTo(iTopLine);   End;End; Procedure TScrollLabelBasic.KeyboardVkLeft(iScroll: Integer; Shift: TShiftState);Begin  If Shift = [ssSHIFT]  Then   Begin     iTextPos:= iTextLeft;     Invalidate;   End  Else If Shift = []  Then   Begin     iTextPos:= iTextPos+iScroll;     If iTextPos > iTextLeft Then iTextPos:= iTextLeft;     Invalidate;   End;End; Procedure TScrollLabelBasic.KeyboardVkRight(iMaxLine, iScroll: Integer; Shift: TShiftState);Begin  If Shift = [ssSHIFT]  Then   Begin     If iMaxLine > Width     Then      Begin        iTextPos:= Width-iMaxLine-10;      Invalidate;      End;   End  Else If Shift = []  Then   Begin     If iMaxLine > Width     Then      Begin        iTextPos:= iTextPos- iScroll;        If iTextPos < Width-iMaxLine        Then iTextPos:= Width-iMaxLine-10;        Invalidate;      End;   End;End; Procedure TScrollLabelBasic.MouseWheelScroll(iMaxLine, iScroll: Integer; Shift: TShiftState; WheelDelta: Integer);Begin  If Shift = []  Then   Begin   If WheelDelta > 0     Then ScrollBy(-1)     Else ScrollBy(+1);   End  Else If Shift = [ssCTRL]  Then   Begin     If WheelDelta > 0     Then ScrolLBy(-ItemsPerPage)     Else ScrolLBy(+ItemsPerPage);   End  Else If Shift = [ssSHIFT]  Then   Begin    If WheelDelta > 0    Then   Begin      If iMaxLine > Width      Then       Begin         iTextPos:= iTextPos+iScroll;         If iTextPos > iTextLeft Then iTextPos:= iTextLeft;         Invalidate;       End;     End    Else   Begin      If iMaxLine > Width      Then       Begin         iTextPos:= iTextPos-iScroll;         If iTextPos < Width-iMaxLine       Then iTextPos:= Width-iMaxLine-10;         Invalidate;       End;     End;   End;End; END. The original can be found here: https://forum.lazarus.freepascal.org/index.php/topic,38151.msg258636.h tml#msg258636