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.

Recommended Answers

All 3 Replies

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

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.

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]);
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.