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

Select ListBox items as mouse hovers over them

By , About.com Guide

Here's how to set the selected item in a ListBox as mouse moves over the list box.

Just assign the next code to the OnMouseMove event handler for the ListBox (ListBox1) component.

~~~~~~~~~~~~~~~~~~~~~~~~~
procedure TForm1.ListBox1MouseMove
   (Sender: TObject; Shift: TShiftState; X, Y: Integer) ;
begin
   ListBox1.ItemIndex := ListBox1.ItemAtPos(Point(x,y), True) ;
end;
~~~~~~~~~~~~~~~~~~~~~~~~~

Delphi tips navigator:
» What's the word under the mouse cursor in a TRichEdit?
« Enable or disable a control by name

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. TMouse
  6. Select ListBox items as mouse hovers over them

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

All rights reserved.