欢迎来到工商注册核名查询系统!

Delphi

当前位置:主页 > 软件编程 > Delphi >

Delphi实现Listbox中的item根据内容显示不同颜 的方法

来源:本站原创|时间:2022-11-25|栏目:Delphi|

本文简述了Delphi实现Listbox中的item根据内容显示不同颜 的方法,实现步骤如下:

ListBox1 的 Style 属性改为 lbOwnerDrawVariable

在ListBox的OnDrawItem 裡,根据item的值,改变Canvas属性

示例代码如下:

procedure TForm1.ListBox1DrawItem(Control: TWinControl; Index: Integer; Rect: TRect; State: TOwnerDrawState);
begin    //字体用原来默认的颜   
 if Odd(index) then   //当items的index为奇数时的颜   
 begin
  listbox1.Canvas.Brush.Color:=clwindow;
  ListBox1.Canvas.TextRect(Rect,rect.Left,Rect.Top,ListBox1.Items[index]);
 end
 else     //当items的index为偶数时的颜   
 begin
  listbox1.Canvas.Brush.Color:=clinactivecaptiontext;
  ListBox1.Canvas.TextRect(Rect,rect.Left,Rect.Top,ListBox1.Items[index]);
 end;
 if  odSelected  in  state  then    //当选定时的颜   
 begin
  listbox1.Canvas.Brush.Color:=clhighlight;
  ListBox1.Canvas.TextRect(Rect,rect.Left,Rect.Top,ListBox1.Items[index]);
 end;
end;

更多Delphi

您可能感兴趣的文章

阅读排行

本栏相关

随机阅读

网页制作CMS教程网络编程软件编程脚本语言数据库服务器

如果侵犯了您的权利,请与我们联系,我们将在24小时内进行处理、任何非本站因素导致的法律后果,本站均不负任何责任。

联系QQ:835971066 | 邮箱:835971066#qq.com(#换成@)

Copyright © 2002-2020 工商注册核名查询系统 版权所有