Board index » cppbuilder » Changing Item color in a TListBox

Changing Item color in a TListBox

Hello,
I am using TListBox to display messages during program execution.
__________________________________________________
FormMain->ListBox1->Items->Add(AnsiString "message1");
__________________________________________________
Some messages (like ERROR messages), I would like to add to
ListBox BUT painted in red color (and all other messages will have same,
default color).
Is this possible/simple in run time mode?
Best regards and thanks all,
Carina
 

Re:Changing Item color in a TListBox


Hi, Carina!

You'll need to use TRichEdit or make the ListBox owner draw, I think.

Also, a grid with a single column may offer some capabilities along the
lines of what you need.

------
Mark Cashman (TeamB - C++ Builder), creator of The Temp{*word*203}Doorway at
http://www.temporaldoorway.com
- Original digital art, writing, music and more -
C++ Builder / JBuilder Tips and The C++ Builder Programmer's Webring
(Join us!)
http://www.temporaldoorway.com/programming/index.htm
------

Re:Changing Item color in a TListBox


Here is some code I used to add color to ListBox items....

void __fastcall TMDIChild::FeesListBoxDrawItem(TWinControl *Control,
      int Index, TRect &Rect, TOwnerDrawState State)
{
// set the color here
if (!(FeeFields[Index]->FeeAmount->AsString.IsEmpty() &&
FeeFields[Index]->FeePercentage->AsString.IsEmpty()))
        FeesListBox->Canvas->Font->Color = clGreen;
    else
        FeesListBox->Canvas->Font->Color = clWindowText;
FeesListBox->Canvas->FillRect(Rect); // paint the background
FeesListBox->Canvas->TextOut(Rect.Left, Rect.Top,
FeesListBox->Items->Strings[Index]);

Quote
}
Carina Rodriguez <cro...@intramed.net.ar> wrote in message

news:380632C8.604FC609@intramed.net.ar...
Quote
> Hello,
> I am using TListBox to display messages during program execution.
> __________________________________________________
> FormMain->ListBox1->Items->Add(AnsiString "message1");
> __________________________________________________
> Some messages (like ERROR messages), I would like to add to
> ListBox BUT painted in red color (and all other messages will have same,
> default color).
> Is this possible/simple in run time mode?
> Best regards and thanks all,
> Carina

Other Threads