Alex Rivera | Logout

Multiple colors in a C# .NET label

Asked 2008-11-09T11:32:11.573
38

I'm looking for a way to display multiple colors in a single C#/.NET label. E.g the label is displaying a series of csv separated values that each take on a color depending on a bucket they fall into. I would prefer not to use multiple labels, as the values are variable length and I don't want to play with dynamic layouts. Is there a native support for this?

Edit
Report

2 Answers

5

As an alternative, you might do this as rtf or html in a suitable control (such as WebBrowser). It would probably take a bit more resources that you'd ideally like, but it'll work fairly quickly.

answered 2008-11-09T11:41:13.210
4

If you are building your Windows app for people with XP and up, you can use WPF. Even if it's a Windows Forms app, you can add a WPF UserControl.

I would then use a Label, and set the "Foreground" property to be a gradient of colors.

Or, in Windows Forms (no WPF), you could just use a "Flow Panel", and then in a for loop add multiple Labels as segments of your sentense... they will all "flow" together as if it was one label.

answered 2008-11-09T12:26:33.367

Your Answer