views:

216

answers:

4

Hi

I'm not sure if it's possible. I wrote a code like this:

listBox1.Items.Add("There are " + countu.ToString().Trim() + " u's");
listBox1.Font = new Font("Arial", 12, FontStyle.Bold);
listBox1.ForeColor = Color.Violet;

listBox1.Items.Add("There are " + j.ToString().Trim() + " vowels");
listBox1.ForeColor = Color.Blue;

When I executed this code, the color of the texts were blue. I would like to have it first "violet" and then the next line of code blue. Is it possible?

Cheers

+1  A: 

ObjectListView, though it's not exactly a ListBox, allows to do that. If you want ListBox only, see this.

Anton Gogolev
+1  A: 

It is possible only if you draw everything your-self (owner-drawn).

Josip Medved
+3  A: 

You could create an owner-drawn listbox as described in MSDN here:

How to: Create an Owner-Drawn List Box

0xA3
A: 

Try using listBox1.Items[currentItem].Attributes.CssStyle to set the color of each item on a granular level.

e: whoops, missed the windows-forms tag. my bad.

Repo Man