Home > DeveloperSection > Forums > Multi-color TextBox C#
Mark Devid
Mark Devid

Total Post:101

Points:707
Posted on    November-14-2013 12:56 AM

 C# C# 
Ratings:


 1 Reply(s)
 2820  View(s)
Rate this:
I want show text in textbox in 2 colors, for example 1 line red 2 blue, if I use name.ForeColor = Color.Red; all text change color, but I want that will change only 1 line color.


Pravesh Singh

Total Post:411

Points:2881
Posted on    November-14-2013 1:21 AM

Use a RichTextBox for this:

public static class RichTextBoxExtensions

{

    public static void AppendText(this RichTextBox box, string text, Color color)

    {

        box.SelectionStart = box.TextLength;

        box.SelectionLength = 0;

        box.SelectionColor = color;

        box.AppendText(text);

        box.SelectionColor = box.ForeColor;

    }

}


Don't want to miss updates? Please click the below button!

Follow MindStick