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

Display Long TListBox Delphi Items as Hints

By , About.com Guide

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

Explore Delphi Programming
About.com Special Features

Holiday Central

What to eat, where to go, fun things to do and how to save money on the perfect gifts. More >

Family Tech Center

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. 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.