procedure TFrmMain.btn1Click(Sender: TObject);
var
Lv1 : TlistView;
begin
if (Lv1.Items[i].Caption = Lv2.Items[i].Caption) and
(Lv1.Items[i].SubItems.strings[0] = Lv2.Items[i].SubItems.strings[0]) then
begin
//显示这一行(ListView这一行)的颜色为 红色;
end
end;
调试欢乐多
if Items.Caption = '红色' then
beign
ListView.Canvas.Font.Color:= clRed;
end;
Item: TListItem; State: TCustomDrawState; var DefaultDraw: Boolean);
var
p:trect;
begin
if cdsselected in state then
begin
listview1.Canvas.Font.Color:=clgreen;
listview1.Canvas.brush.Color:=clred;
p:=item.displayrect(drselectbounds);
listview1.Canvas.FillRect(p);
listview1.Canvas.Textout(p.Left+2,p.Top,item.Caption);
listview1.Canvas.brush.Color:=clblue;
listview1.Canvas.FrameRect(item.displayrect(drselectbounds));
defaultdraw:=false;
end;
end;
Item: TListItem; State: TCustomDrawState; var DefaultDraw: Boolean);
var
R: TRect;
begin
with TListView(Sender).canvas do
if cdsSelected in State then
begin
font.Style := [fsBold];
font.color := clred;
brush.Color := clgreen;
R := item.DisplayRect(drlabel);
textout(R.Left + 1, R.Top + 1, item.Caption);
defaultdraw := False;
end
else
DefaultDraw:=true;
end;
if (Lv1.Items[i].Caption = Lv2.Items[i].Caption) and
(Lv1.Items[i].SubItems.strings[0] = Lv2.Items[i].SubItems.strings[0]) then
begin
//显示这一行(ListView这一行)的颜色为 红色;
//如果满足以上条件,再绘制符合条件的这一行的颜色.
end
procedure TFrmMain.btnClick(Sender: TObject);
var
rect: TRect;
i,x:integer;
begin
if (Lv1.Items[i].Caption = Lv2.Items[i].Caption) and
(Lv1.Items[i].SubItems.strings[0] = Lv2.Items[i].SubItems.strings[0]) then
begin
rect := Lv1.Items[0].DisplayRect(drBounds) ;
Lv1.Canvas.Font.Color := clWhite;
Lv1.Canvas.Brush.Color:= clRed;
Lv1.Canvas.FillRect(rect);
Lv1.Canvas.Textout(rect.left,rect.top,Lv1.Items[0].caption); //
x:=0;
for i:=0 to Lv1.Columns.Count-2 do
begin
x:=x+Lv1.Columns[i].Width;
Lv1.Canvas.Textout(rect.Left+x,rect.Top, Lv1.Items[0].SubItems.Strings[i]);//显示SubItems文字
end;
end;
end;