Используй TListView.
Если все же без TListBox не обойтись, то можно сделать так:
| Код | procedure TForm1.ListBox1MouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer); var ind: Integer; R: TRect; P: TPoint; begin ind := ListBox1.ItemAtPos(Point(X,Y),True); if ind<>-1 then begin if ListBox1.Canvas.TextWidth(ListBox1.Items[Ind])>ListBox1.ClientWidth then begin ListBox1.Hint := ListBox1.Items[Ind]; H.Canvas.Font := ListBox1.Canvas.Font; R := ListBox1.ItemRect(Ind); P := ListBox1.ClientToScreen(R.TopLeft); R.Left := P.X+1; R.Top := P.Y+1; R.Bottom := R.Top+ListBox1.ItemHeight-1; R.Right := R.Left+ListBox1.Canvas.TextWidth(ListBox1.Hint)+4; H.ActivateHint(R,ListBox1.Hint); end else H.ReleaseHandle; end; end;
procedure TForm1.FormCreate(Sender: TObject); begin H := THintWindow.Create(ListBox1); end;
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction); begin H.Free; end;
|
|