• linkedu视频
  • 平面设计
  • 电脑入门
  • 操作系统
  • 办公应用
  • 电脑硬件
  • 动画设计
  • 3D设计
  • 网页设计
  • CAD设计
  • 影音处理
  • 数据库
  • 程序设计
  • 认证考试
  • 信息管理
  • 信息安全
菜单
linkedu.com
  • 网页制作
  • 数据库
  • 程序设计
  • 操作系统
  • CMS教程
  • 游戏攻略
  • 脚本语言
  • 平面设计
  • 软件教程
  • 网络安全
  • 电脑知识
  • 服务器
  • 视频教程
  • JavaScript
  • ASP.NET
  • PHP
  • 正则表达式
  • AJAX
  • JSP
  • ASP
  • Flex
  • XML
  • 编程技巧
  • Android
  • swift
  • C#教程
  • vb
  • vb.net
  • C语言
  • Java
  • Delphi
  • 易语言
  • vc/mfc
  • 嵌入式开发
  • 游戏开发
  • ios
  • 编程问答
  • 汇编语言
  • 微信小程序
  • 数据结构
  • OpenGL
  • 架构设计
  • qt
  • 微信公众号
您的位置:首页 > 程序设计 >Delphi > Delphi实现Listbox中的item根据内容显示不同颜色的方法

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

作者: 字体:[增加 减小] 来源:互联网 时间:2017-05-28

通过本文主要向大家介绍了delphi checklistbox,delphi listbox1,delphi listbox用法,delphi listbox选中,delphi listbox等相关知识,希望对您有所帮助,也希望大家支持linkedu.com www.linkedu.com

本文简述了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;
</div> </div>
分享到:QQ空间新浪微博腾讯微博微信百度贴吧QQ好友复制网址打印

您可能想查找下面的文章:

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

相关文章

  • 2017-05-28Delphi实现限定软件使用时间的方法
  • 2017-05-28Delphi实例演示Rect、Bounds生成TRect的区别
  • 2017-05-28delphi程序全屏显示无标题栏覆盖整个屏幕(适合屏保)
  • 2017-05-28Delphi实现窗口文字淡入淡出渐变效果的方法
  • 2017-05-28delphi建立、读取、存贮INI文件的方法《三》
  • 2017-05-28delphi中一个值得大家来考虑的DLL问题
  • 2017-05-28Delphi实现木马自我拷贝方法
  • 2017-05-28Delphi中判断文件是否为文本文件的函数
  • 2017-05-28Delphi7中群发Email邮件的方法
  • 2017-05-28delphi实现将BMP格式图形转化为JPG格式图形的方法

文章分类

  • JavaScript
  • ASP.NET
  • PHP
  • 正则表达式
  • AJAX
  • JSP
  • ASP
  • Flex
  • XML
  • 编程技巧
  • Android
  • swift
  • C#教程
  • vb
  • vb.net
  • C语言
  • Java
  • Delphi
  • 易语言
  • vc/mfc
  • 嵌入式开发
  • 游戏开发
  • ios
  • 编程问答
  • 汇编语言
  • 微信小程序
  • 数据结构
  • OpenGL
  • 架构设计
  • qt
  • 微信公众号

最近更新的内容

    • Windows API GetLastError()函数返回值含义解释
    • Delphi下OpenGL2d绘图之初始化流程详解
    • delphi 正弦曲线图
    • Delphi修改操作注册表权限的代码
    • Delphi常用关键字用法详解
    • Delphi基本图像处理方法汇总
    • Delphi远程连接Mysql的实现方法
    • delphi实现保存和读取图片的方法
    • delphi实现将BMP格式图形转化为JPG格式图形的方法
    • Delphi控件ListView的属性及使用方法详解

关于我们 - 联系我们 - 免责声明 - 网站地图

©2020-2025 All Rights Reserved. linkedu.com 版权所有