Welcome to Dream.In.Code
Getting C# Help is Easy!

Join 136,157 C# Programmers for FREE! Get instant access to thousands of C# experts, tutorials, code snippets, and more! There are 2,129 people online right now. Registration is fast and FREE... Join Now!




Add items in ListBox with different colors

 
Reply to this topicStart new topic

Add items in ListBox with different colors

cygnusX
5 Dec, 2007 - 02:02 AM
Post #1

D.I.C Head
**

Joined: 19 May, 2007
Posts: 159



Thanked: 2 times
My Contributions
How to add items with different color in ListBox control?This code for example change the colors of all items in the ListBox.
Obviously i do not want that.
CODE

this.listBox1.DrawItem += new DrawItemEventHandler(this.DrawItemHandler);

   private void DrawItemHandler(object sender, DrawItemEventArgs e)
        {
            e.DrawBackground();
            e.DrawFocusRectangle();
            e.Graphics.DrawString(someString,
                                  new Font(FontFamily.GenericSansSerif,
                                           8, FontStyle.Bold),
                                           new SolidBrush(tColor),e.Bounds);
        }

How to achieve what i want?AFAIK i should remove e.Bounds and play with e.Index or something...but don't know what to do exactly.Thanks in advance.
User is offlineProfile CardPM
+Quote Post

William_Wilson
RE: Add Items In ListBox With Different Colors
5 Dec, 2007 - 05:11 PM
Post #2

lost in compilation
Group Icon

Joined: 23 Dec, 2005
Posts: 3,984



Thanked: 16 times
Dream Kudos: 3275
Expert In: Java, C, Javascript

My Contributions
You are already doing it here: new SolidBrush(tColor)
change the colour associated with tColor and you will change the colour the text is displayed as.
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 12/1/08 11:24PM

Live C# Help!

C# Tutorials

Reference Sheets

C# Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month