Delphi实现Listbox中的item根据内容显示不同颜色的方法
2014-07-17 10:30
821 查看
本文简述了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;
您可能感兴趣的文章:
相关文章推荐
- TListbox中的item根据内容显示不同颜色的方法
- DELPHI 让LISTBOX 不同内容的行显示不同颜色
- LigerUi中Grid表记录根据条件显示不同颜色和不同内容!(实例)
- UITextView显示HTML内容,实现显示不同的字体和文字颜色
- shell脚本中echo显示内容带颜色的实现方法
- Android中使用一个textview实现不同颜色以及内容分割的显示
- shell脚本中echo显示内容带颜色的实现方法
- shell脚本中echo显示内容带颜色的实现方法
- Gridview某一列根据不同的条件显示不同颜色的实现(原创)
- C#实现item自定义颜色的ListBox,显示日志
- asp.net中jqgrid根据不同类别头部显示不同的列的实现方法
- destoon实现不同会员组公司名称显示不同的颜色的方法
- 重绘ListBox实现特定行显示不同的颜色
- 关于dorado框架datatable处的右键菜单无法根据具体数据实现动态分别显示不同菜单的解决方法
- iOS中Label实现显示不同颜色与字体的方法
- [delphi]ComboBox实现显示文本与值不同的方法
- shell脚本中echo显示内容带颜色的实现方法
- destoon实现不同会员组公司名称显示不同的颜色的方法
- shell脚本中echo显示内容带颜色的实现方法
- delphi Dbgrid 根据值的不同显示不同颜色