我有一个自定义的DrawItem实现,它适用于最后一项之外的每个项目。这是我的功能:
procedure TFrameBusquedaAvanzada.lstBusquedaListaDrawItem(Control: TWinControl;
Index: Integer; Rect: TRect; State: TOwnerDrawState);
var lGrafico:TIcon;
begin
lGrafico:=nil;
with lstBusquedaLista,(Control as TListBox).Canvas do
begin
lGrafico:=TIcon.Create;
FMain.imageList.GetIcon(TClassCarpeta(Items.Objects[Index]).Icono,lGrafico)
TextRect(Rect,Rect.Left+Margins.Left+24,Rect.Top+6,(Control as TListBox).Items[index]);
if Assigned(lGrafico) then
begin
StretchDraw(System.Classes.Rect(Rect.Left,Rect.Top,Rect.Left+24,Rect.Top+24),lGrafico);
FreeAndNil(lGrafico);
end;
end;
end;
除非选择了最后一项或我在ListBox中滚动,否则图标将不会显示。