Hi I currently have a texbox that prints out info to the user when they press diffrent buttons. I was wondering if there was a way to make only some of my text bolded while
Taking jwillmer's excellent example, I made some adjustments because it was coloring the entire error line for me:
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{ }
}
Also, I added unique tags before and after the text to color to get the text, then removed them.