根据内容在Delphi中着色ListView对象

时间:2017-06-08 20:17:53

标签: delphi

我正在尝试为ListView对象的行着色。颜色意味着在白色和灰色之间交替,并且当行的标题不匹配时,仅在行与行之间不同。例如,如果5行都具有相同的标题并且彼此相邻,那么它们应该都是一种颜色,下一行以交替颜色开始

procedure TMainForm.ListView1CustomDrawItem(Sender: TCustomListView;
  Item: TListItem; State: TCustomDrawState; var DefaultDraw: Boolean);
begin    
if Item.Index = 0 then begin
   sender.Canvas.Brush.Color := $f4f4f4;
   CurrentColor := $f4f4f4;
end
else if (Item.Caption = ListView1.Items[Item.Index + 1].Caption) then begin
  if CurrentColor = clWhite then begin
    sender.Canvas.Brush.Color := clWhite;
    CurrentColor := clWhite;
  end
  else begin//if CurrentColor = $f4f4f4 then begin
    sender.Canvas.Brush.Color := $f4f4f4;
    CurrentColor := $f4f4f4;
  end;
end
else begin
  if CurrentColor = clWhite then begin
    sender.Canvas.Brush.Color := $f4f4f4;
    CurrentColor := $f4f4f4;
  end;
  if CurrentColor = $f4f4f4 then begin
    sender.Canvas.Brush.Color := clWhite;
    CurrentColor := clWhite;
  end;
end
end;

0 个答案:

没有答案