x是什么? 一句例子:实现奇数行的字体为蓝色,写在ListView中的CustomDrawItem事件中 if (Item.Index mod 2) = 0 then (Sender as TCustomListView).Canvas.Font.Color := clSkyBlue;
我是要根据条件啊,X是一个外部的值,决定字体是否有颜色。 我是这么想的 procedure draw(Sender: TCustomListView; Item: TListItem; State: TCustomDrawState; var DefaultDraw: Boolean); begin if x = 1 then WarnMsgList.Canvas.Font.Color := clBlue else WarnMsgList.Canvas.Font.Color := clred; end; 自己写个事件,然后根据我的条件X等于几,让这个事件决定字体的颜色,最后赋给ONCustomDrawItem事件,可以么?我的X怎么传进去?我定义了窗体变量,不行啊
可以的啊。OnCustomDrawItem事件中判断X值就可以了。。 X要定义成全局变量。
可是我根据条件写 if x = 1 then WarnMsgList.Canvas.Font.Color := clBlue else WarnMsgList.Canvas.Font.Color := clred; 他是所有字体的颜色都变了啊?我要新增的一行变颜色,怎么办?
你用个变量来做标志,当标志为FALSE 在Customdraw事件中写;if addflag then begin sender.font.color:=clred; end else begin sender.font.color:=clbule; end; addflag:=false;
NewItem := Listview.Items.Insert(0); with NewItem do begin if x=1 then begin SubItems.Add(); ... //设置字体颜色 end; else //另一种颜色 end; 就是我添加一条的时候,判断其中一个字段的值是什么,然后相应的设置当前添加的一条字体的颜色
一句例子:实现奇数行的字体为蓝色,写在ListView中的CustomDrawItem事件中
if (Item.Index mod 2) = 0 then (Sender as TCustomListView).Canvas.Font.Color := clSkyBlue;
我是这么想的
procedure draw(Sender: TCustomListView;
Item: TListItem; State: TCustomDrawState; var DefaultDraw: Boolean);
begin
if x = 1 then
WarnMsgList.Canvas.Font.Color := clBlue
else
WarnMsgList.Canvas.Font.Color := clred;
end;
自己写个事件,然后根据我的条件X等于几,让这个事件决定字体的颜色,最后赋给ONCustomDrawItem事件,可以么?我的X怎么传进去?我定义了窗体变量,不行啊
X要定义成全局变量。
if x = 1 then
WarnMsgList.Canvas.Font.Color := clBlue
else
WarnMsgList.Canvas.Font.Color := clred;
他是所有字体的颜色都变了啊?我要新增的一行变颜色,怎么办?
在Customdraw事件中写;if addflag then
begin
sender.font.color:=clred;
end else
begin
sender.font.color:=clbule;
end;
addflag:=false;
NewItem := Listview.Items.Insert(0);
with NewItem do
begin
if x=1 then
begin
SubItems.Add();
...
//设置字体颜色
end;
else
//另一种颜色
end;
就是我添加一条的时候,判断其中一个字段的值是什么,然后相应的设置当前添加的一条字体的颜色
只要把RECT的内容重新画一遍就OK了。
在DRAW....中写。呵呵