2009-07-04 11 views
8

C'è un ListBox con alcuni oggetti lunghi. Questi oggetti lunghi vanno oltre il limite destro del ListBox e qui viene l'idea di mostrare suggerimenti per tali elementi quando il mouse si trova su di essi.Suggerimenti lunghi ListBox voci

ho trovato un esempio: (da http://delphi.about.com/cs/adptips2001/a/bltip0201_4.htm)

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; 

Funziona, ma ogni volta che desidera visualizzare un suggerimento per un altro elemento necessario per spostare il mio mouse di distanza dal ListBox e quindi punto su un altro oggetto per vedere il suo suggerimento. C'è un modo per visualizzare suggerimenti per ogni oggetto senza spostare il mouse dai bordi di ListBox?

risposta

11
var fOldIndex: integer = -1; 

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)) ; 

    // this should do the trick.. 
    if fOldIndex <> lstIndex then 
    Application.CancelHint; 
    fOldIndex := lstIndex; 

    if (lstIndex >= 0) and (lstIndex <= Items.Count) then 
    Hint := Items[lstIndex] 
    else 
    Hint := '' 
    end; 
end; 
+0

Bingo! Grazie mille! – Vlad

+0

Non dovrebbe (lstIndex <= Items.Count) essere effettivamente (lstIndex Tom