-1

I tried to use this method, but it changes only the first time that textToMark is shown in the richTextBox and I want it to change every time textToMark is contained:

public static void ChangeTextcolor(string textToMark, Color color, RichTextBox richTextBox)
    {
        int startIndex = 0;

        string text = richTextBox.Text;
        startIndex = text.IndexOf(textToMark);

        System.Drawing.Font newFont = new Font("Verdana", 10f, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, 178, false);

        try
        {
            foreach (string line in richTextBox.Lines)
            {
                if (line.Contains(textToMark))
                {
                    richTextBox.Select(startIndex, textToMark.Length);
                    richTextBox.SelectionColor = color;
                    richTextBox.SelectionFont = newFont;
                }
            }
        }
        catch{ }
    }

Can you help me? Thanks

Failed Scientist
  • 1,977
  • 3
  • 29
  • 48
Ron F
  • 27
  • 1
  • 6

1 Answers1

-1

You can use RichTextBox Control. Formatting Characters in Bold in a RichTextBox Control (Visual C#)

richTextBox1.Rtf = @"{\rtf1\ansi This is in \b bold\b0.}";
mybirthname
  • 17,949
  • 3
  • 31
  • 55