MULTI-COLOR TEXTBOX C#

Mark Devid

Total Post:102

Points:714
Posted by  Mark Devid
C# 
C#
 3775  View(s)
Ratings:
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.
  1. Pravesh Singh

    Post:412

    Points:2888
    Re: Multi-color TextBox C#

    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;

        }

    }

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!