delphi Firemonkey ListBoxItem自绘
ListBoxItem1的事件ListBoxItem1Paint
procedure TForm1.ListBoxItem1Paint(Sender: TObject; Canvas: TCanvas; const ARect: TRectF); begin if (Sender as TListBoxItem).IsSelected then begin Canvas.Fill.Kind := TBrushKind.Solid; Canvas.Fill.Color := TAlphaColorRec.Blue; Canvas.FillRect(ARect, 0, 0, [], 1); Canvas.Fill.Kind := TBrushKind.Solid; Canvas.Fill.Color := TAlphaColorRec.White; Canvas.FillText(ARect, (Sender as TListBoxItem).Text, False, 1, [], TTextAlign.Leading, TTextAlign.Center); end else begin Canvas.Fill.Kind := TBrushKind.Solid; Canvas.Fill.Color := TAlphaColorRec.White; Canvas.FillRect(ARect, 0, 0, [], 1); Canvas.Fill.Color := TAlphaColorRec.Black; Canvas.Fill.Kind := TBrushKind.Solid; Canvas.FillText(ARect, (Sender as TListBoxItem).Text, False, 1, [], TTextAlign.Leading, TTextAlign.Center); end; end;