我用checklistbox框,裡面有10行,我任意選其中3或2行,我希望被選中的行顯示紅色,怎麼做呢?

解决方案 »

  1.   

    checklistbox 不支持单个项的颜色变化  要实现此功能,建议从网上下载一个控件用!
    我提供一个:http://www.ironwareinfo.com.cn/breeze/delphi/Components.asp
      

  2.   

    在checklistbox的DrawItem事件中加入以下代码。
    设置checklistbox的style为lbOwnerDrawFixed。  with (Control as TCheckListBox).Canvas do  { draw on control canvas, not on the form }
    begin
       FillRect(Rect);       { clear the rectangle }
        if ((Control as TCheckListBox).Checked[Index]) then
          Font.Color := clRed
        else
          Font.Color := clblue;     TextOut(Rect.Left , Rect.Top, (Control as TCheckListBox).Items[Index])  { display the text }
    end;