Changing Text to bold or a different colour in a listbox

UG Guru

Newcomer
Joined
Oct 18, 2005
Messages
9
I'm using a listbox to display status of a program that is running.
After an event I add a line of information to the listbox.
I'd like to make this a little bit easier to pick out specific information so I'd like to make some areas of text bold or possibly a different colour.
I'd even like to go as far as making a section of text in one of the lines in the listbox a different colour/bold to the rest of that line.
For example Host123 on network Failed
or Installation of Myprog on Host123 Completed Succesfully
I've seen a complicated solution that draws the listbox with some extra code but I was expecting there to be a simple way of formatting a strings colour, font etc a bit like html tags.

Any help would be great.

Cheers,

UG Guru
 
A standard listbox doesn't provide this capability - the only solution would be to ownerdraw the control yourself.

You may find that using a RichTextBox control instead might be an easierway to solve the problem though.
 
Another option is the ListView control. In "details" view it looks very similar to a ListBox, but allows you to specify fonts and fore/backcolors. The downside is that it takes a little more work to code and it can't contain any type of object except ListViewItem objects (but you could assign their .Tag property to point to the object that they represent if it helps).
 
Back
Top