2009-07-04 11 views
8

Hay un ListBox con algunos elementos largos. Estos artículos largos están yendo más allá del borde derecho de ListBox y aquí viene una idea para mostrar sugerencias de tales elementos cuando el mouse está sobre ellos.elementos largos ListBox indica

he encontrado un ejemplo: (de 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; 

Funciona, pero cada vez que desee ver una indirecta por otro artículo que tengo que mover el ratón de distancia del cuadro de lista y luego punto en otro elemento para ver su sugerencia. ¿Hay alguna manera de ver sugerencias para cada elemento sin alejar el mouse de los bordes de ListBox?

Respuesta

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! ¡Muchas gracias! – Vlad

+0

No debería (lstIndex <= Items.Count) ser en realidad (lstIndex Tom

Cuestiones relacionadas