Multi-color TextBox C#

Total Post:102

Points:714
C# 
C#
 4364  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. 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;
        }
    }

      Modified On Apr-03-2018 05:56:23 AM

Answer

NEWSLETTER

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