this is my very trivial example that should color differently the items in a ListBox when a directory exists or does not exist. Is there a better way without using the ListBox1DrawItem event and keeping the lbStandard Style?
thank you
Code: Select all
void __fastcall TForm1::Button3Click(TObject *Sender)
{
TRect TheRect;
//Rect(int ALeft, int ATop, int ARight, int ABottom);
for(int i=0; i<ListBox1->Items->Count; i++)
{
TheRect = Rect(0,20*i,200,20*i);
// eliminate artifacts
ListBox1->Canvas->FillRect(TheRect);
DWORD dwAttr = GetFileAttributes(ListBox1->Items->Strings[i].c_str());
if(dwAttr == FILE_ATTRIBUTE_DIRECTORY)
{
// color the line
ListBox1->Canvas->Brush->Color = clRed;
ListBox1->Canvas->FillRect(TheRect);
}
else
{
ListBox1->Canvas->Brush->Color = clGreen;
ListBox1->Canvas->FillRect(TheRect);
}
// render the text
ListBox1->Canvas->TextOut( TheRect.Left + 1, TheRect.Top, ListBox1->Items->Strings[i]);
}
}
//---------------------------------------------------------------------------