Change color of text within a label or radio button

Posted on 2007-07-26
Last Modified: 2013-11-26
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!
Question by:ironwill96
    LVL 96

    Expert Comment

    by:Bob Learned
    No, that is not natively possible.  You could probably find something or come up with something like a custom control.

    LVL 22

    Accepted Solution

    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.

    Featured Post

    Training Course: Java/J2EE and SOA

    This course will cover both core and advanced Java concepts like Database connectivity, Threads, Exception Handling, Collections, JSP, Servlets, XMLHandling, and more. You'll also learn various Java frameworks like Hibernate and Spring.

    Join & Write a Comment

    This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
    Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
    It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
    This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor ( If you're looking for how to monitor bandwidth using netflow or packet s…

    728 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now