Delphi實(shí)現(xiàn)Listbox中的item根據(jù)內(nèi)容顯示不同顏色的方法
本文簡(jiǎn)述了Delphi實(shí)現(xiàn)Listbox中的item根據(jù)內(nèi)容顯示不同顏色的方法,實(shí)現(xiàn)步驟如下:
ListBox1 的 Style 屬性改為 lbOwnerDrawVariable
在ListBox的OnDrawItem事件裡,根據(jù)item的值,改變Canvas屬性
示例代碼如下:
procedure TForm1.ListBox1DrawItem(Control: TWinControl; Index: Integer; Rect: TRect; State: TOwnerDrawState); begin //字體用原來(lái)默認(rèn)的顏色 if Odd(index) then //當(dāng)items的index為奇數(shù)時(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ù)時(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)選定時(shí)的顏色 begin listbox1.Canvas.Brush.Color:=clhighlight; ListBox1.Canvas.TextRect(Rect,rect.Left,Rect.Top,ListBox1.Items[index]); end; end;
- delphi實(shí)現(xiàn)保存和讀取圖片的方法
- Delphi遠(yuǎn)程連接Mysql的實(shí)現(xiàn)方法
- Delphi創(chuàng)建開機(jī)啟動(dòng)項(xiàng)的方法示例
- Delphi實(shí)現(xiàn)木馬自我拷貝方法
- Delphi實(shí)現(xiàn)窗口文字淡入淡出漸變效果的方法
- Delphi實(shí)現(xiàn)獲取磁盤空間大小的方法
- Delphi中對(duì)時(shí)間操作方法匯總
- Delphi控件ListView的屬性及使用方法詳解
- delphi7連接mysql5的實(shí)現(xiàn)方法
- Delphi7中群發(fā)Email郵件的方法
相關(guān)文章
Delphi創(chuàng)建開機(jī)啟動(dòng)項(xiàng)的方法示例
這篇文章主要介紹了Delphi創(chuàng)建開機(jī)啟動(dòng)項(xiàng)的方法,很有實(shí)用價(jià)值,需要的朋友可以參考下2014-07-07Delphi實(shí)現(xiàn)獲取進(jìn)程列表及相關(guān)信息的實(shí)例
這篇文章主要介紹了Delphi實(shí)現(xiàn)獲取進(jìn)程列表及相關(guān)信息的實(shí)例,希望通過本文大家能實(shí)現(xiàn)這樣的功能,需要的朋友可以參考下2017-09-09Delphi實(shí)現(xiàn)毫秒級(jí)別的倒計(jì)時(shí)實(shí)例代碼
這篇文章主要介紹了Delphi實(shí)現(xiàn)毫秒級(jí)別的倒計(jì)時(shí)實(shí)例代碼,需要的朋友可以參考下2014-07-07