Delphi實現(xiàn)Listbox中的item根據(jù)內(nèi)容顯示不同顏色的方法
本文簡述了Delphi實現(xiàn)Listbox中的item根據(jù)內(nèi)容顯示不同顏色的方法,實現(xiàn)步驟如下:
ListBox1 的 Style 屬性改為 lbOwnerDrawVariable
在ListBox的OnDrawItem事件裡,根據(jù)item的值,改變Canvas屬性
示例代碼如下:
procedure TForm1.ListBox1DrawItem(Control: TWinControl; Index: Integer; Rect: TRect; State: TOwnerDrawState); begin //字體用原來默認(rèn)的顏色 if Odd(index) then //當(dāng)items的index為奇數(shù)時的顏色 begin listbox1.Canvas.Brush.Color:=clwindow; ListBox1.Canvas.TextRect(Rect,rect.Left,Rect.Top,ListBox1.Items[index]); end else //當(dāng)items的index為偶數(shù)時的顏色 begin listbox1.Canvas.Brush.Color:=clinactivecaptiontext; ListBox1.Canvas.TextRect(Rect,rect.Left,Rect.Top,ListBox1.Items[index]); end; if odSelected in state then //當(dāng)選定時的顏色 begin listbox1.Canvas.Brush.Color:=clhighlight; ListBox1.Canvas.TextRect(Rect,rect.Left,Rect.Top,ListBox1.Items[index]); end; end;
欄 目:Delphi
下一篇:Delphi2007編譯的程序在Win7下圖標(biāo)模糊的解決辦法
本文標(biāo)題:Delphi實現(xiàn)Listbox中的item根據(jù)內(nèi)容顯示不同顏色的方法
本文地址:http://mengdiqiu.com.cn/a1/Delphi/8617.html
您可能感興趣的文章
- 01-10在Delphi實現(xiàn)在數(shù)據(jù)庫中存取圖像的圖文演示無錯
- 01-10delphi建立、讀取、存貯INI文件的方法《三》
- 01-10Delphi Command模式
- 01-10delphi 正弦曲線圖
- 01-10delphi建立、讀取、存貯INI文件的方法《二》
- 01-10插件管理框架 for Delphi(二)
- 01-10插件管理框架 for Delphi(一)
- 01-10Delphi中判斷文件是否為文本文件的函數(shù)
- 01-10delphi中一個值得大家來考慮的DLL問題
- 01-10初探Delphi中的插件編程


閱讀排行
本欄相關(guān)
- 01-10在Delphi實現(xiàn)在數(shù)據(jù)庫中存取圖像的圖
- 01-10delphi建立、讀取、存貯INI文件的方法
- 01-10delphi 正弦曲線圖
- 01-10Delphi Command模式
- 01-10delphi建立、讀取、存貯INI文件的方法
- 01-10插件管理框架 for Delphi(二)
- 01-10插件管理框架 for Delphi(一)
- 01-10Delphi中判斷文件是否為文本文件的函
- 01-10delphi中一個值得大家來考慮的DLL問題
- 01-10初探Delphi中的插件編程
隨機閱讀
- 08-05DEDE織夢data目錄下的sessions文件夾有什
- 01-10使用C語言求解撲克牌的順子及n個骰子
- 01-10SublimeText編譯C開發(fā)環(huán)境設(shè)置
- 01-11Mac OSX 打開原生自帶讀寫NTFS功能(圖文
- 01-10C#中split用法實例總結(jié)
- 04-02jquery與jsp,用jquery
- 08-05織夢dedecms什么時候用欄目交叉功能?
- 08-05dedecms(織夢)副欄目數(shù)量限制代碼修改
- 01-10delphi制作wav文件的方法
- 01-11ajax實現(xiàn)頁面的局部加載