我尝试使用此方法,但它仅在richTextBox
中第一次显示textToMark
时更改,并且我希望每次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{ }
}
包含时更改{/ 1}}:
data
你能帮帮我吗?
感谢
答案 0 :(得分:-1)
您可以使用RichTextBox Control。 Formatting Characters in Bold in a RichTextBox Control (Visual C#)
richTextBox1.Rtf = @"{\rtf1\ansi This is in \b bold\b0.}";