Change color of text within a label or radio button

I am trying to color a portion of the text within a radio button or a label in C# (Visual Studio 2005 .Net 2.0).  Is there a way to do this?

An example would be in the following bit of text if placed within a label: "This is some text, RED TEXT HERE back to black text here".  Is there a way to pass color values to be parsed by VS inside the text property of a radio button or a label?

Thanks in advance!
Who is Participating?
DarkoLordConnect With a Mentor Commented:
You can create a custom class that derives from OptionButton (or Label) and override the OnPaint event:

    public class ColorRadioButton : RadioButton
        protected override void OnPaint(PaintEventArgs pevent)
            // creates the control as usual
            // clears the previous text so it doesnt get overwritten (example only)
            base.Text = "             ";
            // draws the red and then blue text (manually positioned, though)
            pevent.Graphics.DrawString("red ", new Font("Arial", 10), Brushes.Red, 15, 0);
            pevent.Graphics.DrawString("blue", new Font("Arial", 10), Brushes.Blue, 35, 0);

Then just change the references to RadioButton class to the ColorRadioButton class in the designer codebehind file.

Note that this is a very simple example. You still have to think of a way how to pass the colors through the Text property and how to position the text portions, though.
Bob LearnedCommented:
No, that is not natively possible.  You could probably find something or come up with something like a custom control.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.