参考:VCL下ListBox自画,Lazarus也一样

 uses LCLType;       

 

 ListBox的两个设置:

自画事件:ListBox1DrawItem

procedure TForm1.ListBox1DrawItem(Control: TWinControl; Index: Integer;
  ARect: TRect; State: TOwnerDrawState);
begin
    With ListBox1.Canvas Do
    Begin
      Brush.Color := $00FF9184; //设置背景颜色并填充背景
      FillRect(aRect);

      Brush.Color := clBlack; //设置圆角矩形颜色并画出圆角矩形
      Pen.Color := $00131315;
      RoundRect(aRect.Left + 3, aRect.Top + 3, aRect.Right - 3, aRect.Bottom - 3, 5, 5);

      Brush.Color := $00A2F9F0;
      Pen.Color := clInfoBk;
      RoundRect(aRect.Left + 3, aRect.Top + 3, aRect.Right - 6, aRect.Bottom - 6, 5, 5); //以不同的宽度和高度再画一次,实现立体效果

      If (odSelected In State) Then {//如果是当前选中项}
      Begin
        Brush.Color := $00BBBBFF; //以不同的背景色画出选中项的圆角矩形
        RoundRect(aRect.Left + 3, aRect.Top + 3, aRect.Right - 3, aRect.Bottom - 3, 5, 5); //选中项的文字颜色
      End;
      ImageList1.Draw(ListBox1.Canvas, aRect.Left + 6, //画出图标
        aRect.Top ,
        index, true);

      Font.Color := clRed; //分别绘出各行文字
      TextOut(aRect.Left + ImageList1.Width + 10, aRect.Top + 4,ListBox1.Items[index]);
      Font.Color := $0F01630E;


      TextOut(aRect.Left + ImageList1.Width + 10, aRect.Top+20, '文章总数: a' );

      If (odFocused In State) Then ListBox1.Canvas.DrawFocusRect(aRect);
    End;
End;
       

 先要设置 ImageList1的宽和高,再导入图片,否则,图片会被清空。

测试图标下载:

链接:https://pan.baidu.com/s/1eCLTHlpc06CwH1WL9AgHkw
提取码:83rn