Sign in Join
Wiki copytemporary

ATListbox

About

ATListbox is OS-independant listbox control. It's made for dialog like Sublime Text's command list. If OnDrawItem is set, listbox is fully owner-drawn: you must not set items, just set ItemCount, ItemIndex.

Listbox doesn't get focus by click; to get focus on click set CanGetFocus=true (if focused, it handles keys Up/Down/PgUp/PgDn/Home/End, else you need to handle OnKeyDown in form and set listbox's ItemIndex by hand, which is boring).

Author: Alexey Torgashin

Screenshot:

Download

Homepage at github: https://github.com/Alexey-T/ATFlatControls

License

MPL 2.0 or LGPL.

Properties

Events

Example

Let's create list:

pascal
uses Math, ATListbox; //package atflatcontrols_package.lpk

var
  b: TATListbox;

procedure TfmMain.FormCreate(Sender: TObject);
begin
  b:= TATListbox.Create(Self);
  b.Parent:= Self;
  b.Align:= alClient;

  b.OnDrawItem:= @ListDraw;
  b.OnClick:= @ListClick;   //see example in github https://github.com/Alexey-T/ATFlatControls/blob/master/app/demo_listbox/unit1.pas

  b.Color:= $e0e0e0;
  b.ItemCount:= 21;
end;

Let's set OnDrawItem to this (simply paint "itemNN"):

pascal
procedure TfmMain.ListDraw(Sender: TObject; C: TCanvas; AIndex: integer;
  const ARect: TRect);
begin
  C.Brush.Color:= IfThen(AIndex=b.ItemIndex, clMedGray, b.Color);
  C.FillRect(ARect);

  C.Pen.Color:= clMedGray;
  C.Line(ARect.Left+2, ARect.Bottom-1, ARect.Right-2, ARect.Bottom-1);

  C.TextOut(ARect.Left+6, ARect.Top+2, 'item '+inttostr(AIndex));
end;

From the Free Pascal wiki, page "ATListbox", as it stood on 2021-12-16 after a change by Alextp, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's Licensing page. If you have concerns about this material, message the admin.

Revision 2, last changed by WikiArchive .

Talk about this page

Nobody has opened a bench for this page yet. Sign in to open one.