1. Home
  2. Computing & Technology
  3. Delphi Programming

Display Long TListBox Delphi Items as Hints

By Zarko Gajic, About.com

Sometimes the data you want to display in a list is too long for the size of ListBox you can use. When this happens, you can use the simple code to display the ListBox entries as Hints when the mouse passes over the ListBox. Just make sure that ShowHints is True.

Drop a TLIstBox (name: ListBox1) on a Delphi form (name: Form1) and handle the OnMouseMove event as:

procedure TForm1.ListBox1MouseMove (Sender: TObject; Shift: TShiftState; X, Y: Integer) ;
var lstIndex : Integer ;
begin
  with ListBox1 do
  begin
   lstIndex:=SendMessage(Handle, LB_ITEMFROMPOINT, 0, MakeLParam(x,y)) ;
   if (lstIndex >= 0) and (lstIndex <= Items.Count) then
     Hint := Items[lstIndex]
   else
     Hint := ''
   end;
  end;
end.

Delphi tips navigator:
» Add a Check Box to a standard dialog box
« Copying group of files - standard animation dialog

Zarko Gajic
Guide since 1998

Zarko Gajic
Delphi Programming Guide

Explore Delphi Programming
About.com Special Features

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

Easy ways to connect two computers for networking purposes. More >

  1. Home
  2. Computing & Technology
  3. Delphi Programming
  4. Using VCL Components
  5. TListBox
  6. Display Long TListBox Delphi Items as Hints

©2009 About.com, a part of The New York Times Company.

All rights reserved.