Making a logbook using editbox for entries that fill a listbox. I have two enter buttons. One would enter line in Red one in Black but I don't know how to change the font color in the listbox. My first pascal program and this is the last step for completion.:( I'm total noob so please explain clearly.

6 Years
Discussion Span
Last Post by pritaeas

You cannot simply change the font per line in a TListBox, without adding some additional coding.

Yes I know. Change the event of ondrawItem. But can it be done with an easy bit of code. I know how to color an individual line or every other line but not how to tie the color to anything but the index.

Edited by BorisSobad: n/a


Well, if you know that already then it is relatively simple. The Items property of a TListBox has an AddObject method. You can use it when adding your string like this:

// clRed is an Integer, and you just cast it to an object
// so it can be added alongside your item text.
ListBox1.Items.AddObject('item', TObject(clRed));

// In your OnDrawItem (color is a TColor variable)
// where i is the index of your current item.
color := TColor(ListBox.Items.Objects[i]);

Edited by pritaeas: n/a

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.