https://www.packtpub.com/en-us/product/delphi-cookbook-second-edition-9781785287428/chapter/delphi-basics-1/section/using-owner-draw-combos-and-listboxes-ch01lvl1sec12

 VCL下ListBox自画,Lazarus也一样   

Delphi10.3ComboBoxEx下拉左边带图标

通过百度网盘分享的文件:listBoxOwnerDrawdd.rar
链接:https://pan.baidu.com/s/1mwesuIyLHsb6j9PFZNLiTQ
提取码:u181

 

procedure TForm7.ListBox1DrawItem(Control: TWinControl; Index: Integer;   Rect: TRect; State: TOwnerDrawState);
var
LBox: TListBox;
R: TRect;
S: string;
TextTopPos, TextLeftPos, TextHeight: Integer;
const
IMAGE_TEXT_SPACE = 4;       //  图标 与 文本 之间  的  间隔
begin
LBox := Control as TListBox;

R := Rect;
LBox.Canvas.FillRect(R);
ImageList1.Draw(LBox.Canvas, R.Left, R.Top, Index);   //画 图标

S := LBox.Items[Index];
TextHeight := LBox.Canvas.TextHeight(S);
TextLeftPos := R.Left +   ImageList1.Width + IMAGE_TEXT_SPACE;
TextTopPos := R.Top + R.Height div 2 - TextHeight div 2  ;
LBox.Canvas.TextOut(TextLeftPos, TextTopPos, S);      //画 文本
end;