问:TListView控件中的OnCustomDrawSubItem()和OnAdvancedCustomDrawSubItem()两事件怎么用啊?

wangchinaking 2003-12-26 02:34:44
帮助中说,要将OwnerDraw属性设置成False时,上述两事件才会触发.
可是,我并没有发现这两个事件能够绘画"SubItems"里的东西,包括字体,
背景,色彩等, 既然不能修改SubItem,为什么还要叫"...DrawSubItem()"呢?
请问大家,有谁知道怎么做才能绘画SubItem内容,包括字体/色彩等??
最好附上代码说明, 因为语言还是太难描述了.
...全文
194 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
wangchinaking 2003-12-26
  • 打赏
  • 举报
回复
谢谢 zswangII(伴水清清)(职业清洁工) 的启发, 如下是我已经实现的代码: :P

with Sender.Canvas do
begin
case Pred (SubItem) of
0:
begin
if 0 = CompareText ('11', Item.SubItems.Strings[Pred (SubItem)]) then
begin
Font.Color := clRed;
Font.Style := [fsBold];
end
else if 0 = CompareText ('21', Item.SubItems.Strings[Pred (SubItem)]) then
begin
Font.Color := clLime;
Font.Style := [fsBold];
end
else if 0 = CompareText ('31', Item.SubItems.Strings[Pred (SubItem)]) then
begin
Font.Color := clHotLight;
Font.Style := [fsBold];
end;
end;
1:
begin
if 0 = CompareText ('12', Item.SubItems.Strings[Pred (SubItem)]) then
begin
Font.Color := clLime;
Font.Style := [fsBold];
end else
if 0 = CompareText ('22', Item.SubItems.Strings[Pred (SubItem)]) then
begin
Font.Color := clRed;
Font.Style := [fsBold];
end else
if 0 = CompareText ('32', Item.SubItems.Strings[Pred (SubItem)]) then
begin
Font.Color := clSkyBlue;
Font.Style := [fsBold];
end;
end;
2:
begin
if 0 = CompareText ('13', Item.SubItems.Strings[Pred (SubItem)]) then
begin
Font.Color := clYellow;
Font.Style := [fsBold];
end;
if 0 = CompareText ('23', Item.SubItems.Strings[Pred (SubItem)]) then
begin
Font.Color := clLime;
Font.Style := [fsBold];
end;
if 0 = CompareText ('33', Item.SubItems.Strings[Pred (SubItem)]) then
begin
Font.Color := clFuchsia;
Font.Style := [fsBold];
end;
end;
else
Font.Color := clHighLight;
end;
end;


搞定!
zswangII 2003-12-26
  • 打赏
  • 举报
回复
那是靠条件判断的~~只要条件符合就处理呗~~
wangchinaking 2003-12-26
  • 打赏
  • 举报
回复
多个Cell的颜色?
wangchinaking 2003-12-26
  • 打赏
  • 举报
回复
怎么单独修改某一个Cell里的颜色呢?
wangchinaking 2003-12-26
  • 打赏
  • 举报
回复
字体色彩呢? 你只修改了字体的方式, 尤其是SubItem, 好像不能修改似的!
zswangII 2003-12-26
  • 打赏
  • 举报
回复
//OwnerDraw不用设置为False就可以触发了~~
procedure TForm1.ListView1AdvancedCustomDrawItem(Sender: TCustomListView;
Item: TListItem; State: TCustomDrawState; Stage: TCustomDrawStage;
var DefaultDraw: Boolean);
begin
if Odd(Item.Index) then begin
Sender.Canvas.Font.Color := clRed;
Sender.Canvas.Brush.Color := clBlue;
end;
end;

procedure TForm1.ListView1AdvancedCustomDrawSubItem(
Sender: TCustomListView; Item: TListItem; SubItem: Integer;
State: TCustomDrawState; Stage: TCustomDrawStage;
var DefaultDraw: Boolean);
begin
if Odd(Item.Index) then begin
Sender.Canvas.Font.Color := clRed;
Sender.Canvas.Brush.Color := clBlue;
end;
if Odd(SubItem) then
Sender.Canvas.Font.Style := [fsBold];
end;

5,388

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 开发及应用
社区管理员
  • VCL组件开发及应用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧